claude-smart 0.2.41 → 0.2.43

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 (396) hide show
  1. package/.claude-plugin/marketplace.json +17 -0
  2. package/README.md +1 -1
  3. package/bin/claude-smart.js +86 -48
  4. package/package.json +10 -3
  5. package/plugin/.claude-plugin/plugin.json +9 -3
  6. package/plugin/.codex-plugin/plugin.json +1 -1
  7. package/plugin/README.md +2 -2
  8. package/plugin/dashboard/next.config.ts +9 -1
  9. package/plugin/pyproject.toml +2 -2
  10. package/plugin/scripts/_lib.sh +91 -0
  11. package/plugin/scripts/backend-service.sh +46 -15
  12. package/plugin/scripts/cli.sh +29 -1
  13. package/plugin/scripts/codex-hook.js +72 -4
  14. package/plugin/scripts/dashboard-build.sh +1 -0
  15. package/plugin/scripts/dashboard-service.sh +1 -0
  16. package/plugin/scripts/ensure-plugin-root.sh +7 -14
  17. package/plugin/scripts/hook_entry.sh +1 -0
  18. package/plugin/scripts/smart-install.sh +18 -2
  19. package/plugin/src/claude_smart/cli.py +72 -38
  20. package/plugin/src/claude_smart/context_format.py +11 -12
  21. package/plugin/src/claude_smart/cs_cite.py +26 -12
  22. package/plugin/src/claude_smart/ids.py +13 -5
  23. package/plugin/uv.lock +1 -1
  24. package/plugin/vendor/reflexio/.env.example +53 -0
  25. package/plugin/vendor/reflexio/LICENSE +201 -0
  26. package/plugin/vendor/reflexio/README.md +338 -0
  27. package/plugin/vendor/reflexio/pyproject.toml +271 -0
  28. package/plugin/vendor/reflexio/reflexio/README.md +184 -0
  29. package/plugin/vendor/reflexio/reflexio/__init__.py +166 -0
  30. package/plugin/vendor/reflexio/reflexio/benchmarks/__init__.py +1 -0
  31. package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/README.md +109 -0
  32. package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/__init__.py +1 -0
  33. package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/backends.py +175 -0
  34. package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/bench.py +642 -0
  35. package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/embed_cache.py +330 -0
  36. package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/report.py +317 -0
  37. package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/results/report.md +43 -0
  38. package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/results/results.json +4478 -0
  39. package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/scenarios.py +134 -0
  40. package/plugin/vendor/reflexio/reflexio/benchmarks/retrieval_latency/seed.py +255 -0
  41. package/plugin/vendor/reflexio/reflexio/cli/README.md +287 -0
  42. package/plugin/vendor/reflexio/reflexio/cli/__init__.py +0 -0
  43. package/plugin/vendor/reflexio/reflexio/cli/__main__.py +56 -0
  44. package/plugin/vendor/reflexio/reflexio/cli/_client.py +86 -0
  45. package/plugin/vendor/reflexio/reflexio/cli/app.py +127 -0
  46. package/plugin/vendor/reflexio/reflexio/cli/bootstrap_config.py +266 -0
  47. package/plugin/vendor/reflexio/reflexio/cli/codex_auth.py +503 -0
  48. package/plugin/vendor/reflexio/reflexio/cli/commands/__init__.py +0 -0
  49. package/plugin/vendor/reflexio/reflexio/cli/commands/admin_cmd.py +65 -0
  50. package/plugin/vendor/reflexio/reflexio/cli/commands/agent_playbooks.py +503 -0
  51. package/plugin/vendor/reflexio/reflexio/cli/commands/api.py +114 -0
  52. package/plugin/vendor/reflexio/reflexio/cli/commands/auth.py +109 -0
  53. package/plugin/vendor/reflexio/reflexio/cli/commands/config_cmd.py +511 -0
  54. package/plugin/vendor/reflexio/reflexio/cli/commands/doctor.py +127 -0
  55. package/plugin/vendor/reflexio/reflexio/cli/commands/embeddings.py +53 -0
  56. package/plugin/vendor/reflexio/reflexio/cli/commands/interactions.py +478 -0
  57. package/plugin/vendor/reflexio/reflexio/cli/commands/profiles.py +303 -0
  58. package/plugin/vendor/reflexio/reflexio/cli/commands/services.py +289 -0
  59. package/plugin/vendor/reflexio/reflexio/cli/commands/setup_cmd.py +961 -0
  60. package/plugin/vendor/reflexio/reflexio/cli/commands/shortcuts.py +285 -0
  61. package/plugin/vendor/reflexio/reflexio/cli/commands/status_cmd.py +143 -0
  62. package/plugin/vendor/reflexio/reflexio/cli/commands/user_playbooks.py +373 -0
  63. package/plugin/vendor/reflexio/reflexio/cli/env_loader.py +284 -0
  64. package/plugin/vendor/reflexio/reflexio/cli/errors.py +217 -0
  65. package/plugin/vendor/reflexio/reflexio/cli/log_format.py +247 -0
  66. package/plugin/vendor/reflexio/reflexio/cli/output.py +867 -0
  67. package/plugin/vendor/reflexio/reflexio/cli/paths.py +41 -0
  68. package/plugin/vendor/reflexio/reflexio/cli/run_services.py +391 -0
  69. package/plugin/vendor/reflexio/reflexio/cli/state.py +204 -0
  70. package/plugin/vendor/reflexio/reflexio/cli/stop_services.py +96 -0
  71. package/plugin/vendor/reflexio/reflexio/cli/utils.py +329 -0
  72. package/plugin/vendor/reflexio/reflexio/client/__init__.py +3 -0
  73. package/plugin/vendor/reflexio/reflexio/client/cache.py +150 -0
  74. package/plugin/vendor/reflexio/reflexio/client/client.py +2613 -0
  75. package/plugin/vendor/reflexio/reflexio/defaults.py +23 -0
  76. package/plugin/vendor/reflexio/reflexio/integrations/__init__.py +0 -0
  77. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/.clawhubignore +7 -0
  78. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/README.md +274 -0
  79. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/TESTING.md +517 -0
  80. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/hook/handler.js +473 -0
  81. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/package-lock.json +2156 -0
  82. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/package.json +18 -0
  83. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/hook/handler.ts +241 -0
  84. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/hook/setup.ts +140 -0
  85. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/index.ts +130 -0
  86. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/lib/publish.ts +113 -0
  87. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/lib/search.ts +52 -0
  88. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/lib/server.ts +103 -0
  89. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/lib/sqlite-buffer.ts +156 -0
  90. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/lib/user-id.ts +134 -0
  91. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/openclaw.plugin.json +41 -0
  92. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/package.json +17 -0
  93. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/rules/reflexio.md +24 -0
  94. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/skills/reflexio/SKILL.md +48 -0
  95. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/publish_clawhub.sh +278 -0
  96. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/references/HOOK.md +164 -0
  97. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/scripts/install.sh +36 -0
  98. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/scripts/uninstall.sh +35 -0
  99. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/publish.test.ts +27 -0
  100. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/search.test.ts +31 -0
  101. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/server.test.ts +42 -0
  102. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/setup.test.ts +49 -0
  103. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/sqlite-buffer.test.ts +91 -0
  104. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/user-id.test.ts +50 -0
  105. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tsconfig.json +16 -0
  106. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/types/openclaw.d.ts +230 -0
  107. package/plugin/vendor/reflexio/reflexio/integrations/openclaw/vitest.config.ts +13 -0
  108. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/README.md +120 -0
  109. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/TESTING.md +168 -0
  110. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/package-lock.json +1657 -0
  111. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/package.json +16 -0
  112. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/HEARTBEAT.md +6 -0
  113. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/README.md +84 -0
  114. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/SKILL.md +194 -0
  115. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/_meta.json +6 -0
  116. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/agents/reflexio-extractor.md +45 -0
  117. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/hook/handler.ts +214 -0
  118. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/hook/setup.ts +55 -0
  119. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/index.ts +327 -0
  120. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/lib/consolidate.ts +233 -0
  121. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/lib/dedup.ts +80 -0
  122. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/lib/io.ts +155 -0
  123. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/lib/openclaw-cli.ts +67 -0
  124. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/lib/search.ts +33 -0
  125. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/lib/write-playbook.ts +76 -0
  126. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/lib/write-profile.ts +79 -0
  127. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/openclaw.plugin.json +46 -0
  128. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/package.json +18 -0
  129. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/prompts/README.md +36 -0
  130. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/prompts/full_consolidation.md +56 -0
  131. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/prompts/playbook_extraction.md +217 -0
  132. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/prompts/profile_extraction.md +132 -0
  133. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/skills/reflexio-consolidate/SKILL.md +33 -0
  134. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/plugin/skills/reflexio-embedded/SKILL.md +194 -0
  135. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/references/HOOK.md +18 -0
  136. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/references/architecture.md +49 -0
  137. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/references/comparison.md +31 -0
  138. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/references/future-work.md +47 -0
  139. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/references/porting-notes.md +52 -0
  140. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/scripts/install.sh +52 -0
  141. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/scripts/uninstall.sh +36 -0
  142. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/tests/consolidate.test.ts +135 -0
  143. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/tests/dedup.test.ts +104 -0
  144. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/tests/io.test.ts +175 -0
  145. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/tests/search.test.ts +66 -0
  146. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/tests/smoke-test.ts +140 -0
  147. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/tests/write-playbook.test.ts +93 -0
  148. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/tests/write-profile.test.ts +174 -0
  149. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/tsconfig.json +16 -0
  150. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/types/openclaw.d.ts +230 -0
  151. package/plugin/vendor/reflexio/reflexio/integrations/openclaw-embedded/vitest.config.ts +7 -0
  152. package/plugin/vendor/reflexio/reflexio/lib/__init__.py +23 -0
  153. package/plugin/vendor/reflexio/reflexio/lib/_agent_playbook.py +310 -0
  154. package/plugin/vendor/reflexio/reflexio/lib/_base.py +225 -0
  155. package/plugin/vendor/reflexio/reflexio/lib/_config.py +83 -0
  156. package/plugin/vendor/reflexio/reflexio/lib/_dashboard.py +266 -0
  157. package/plugin/vendor/reflexio/reflexio/lib/_generation.py +176 -0
  158. package/plugin/vendor/reflexio/reflexio/lib/_interactions.py +334 -0
  159. package/plugin/vendor/reflexio/reflexio/lib/_operations.py +153 -0
  160. package/plugin/vendor/reflexio/reflexio/lib/_profiles.py +545 -0
  161. package/plugin/vendor/reflexio/reflexio/lib/_reflection.py +52 -0
  162. package/plugin/vendor/reflexio/reflexio/lib/_search.py +167 -0
  163. package/plugin/vendor/reflexio/reflexio/lib/_storage_labels.py +103 -0
  164. package/plugin/vendor/reflexio/reflexio/lib/_user_playbook.py +288 -0
  165. package/plugin/vendor/reflexio/reflexio/lib/reflexio_lib.py +27 -0
  166. package/plugin/vendor/reflexio/reflexio/models/__init__.py +0 -0
  167. package/plugin/vendor/reflexio/reflexio/models/api_schema/__init__.py +0 -0
  168. package/plugin/vendor/reflexio/reflexio/models/api_schema/braintrust_schema.py +141 -0
  169. package/plugin/vendor/reflexio/reflexio/models/api_schema/common.py +41 -0
  170. package/plugin/vendor/reflexio/reflexio/models/api_schema/domain/__init__.py +3 -0
  171. package/plugin/vendor/reflexio/reflexio/models/api_schema/domain/entities.py +1103 -0
  172. package/plugin/vendor/reflexio/reflexio/models/api_schema/domain/enums.py +63 -0
  173. package/plugin/vendor/reflexio/reflexio/models/api_schema/eval_overview_schema.py +487 -0
  174. package/plugin/vendor/reflexio/reflexio/models/api_schema/internal_schema.py +28 -0
  175. package/plugin/vendor/reflexio/reflexio/models/api_schema/pending_tool_call_schema.py +83 -0
  176. package/plugin/vendor/reflexio/reflexio/models/api_schema/retriever_schema.py +766 -0
  177. package/plugin/vendor/reflexio/reflexio/models/api_schema/service_schemas.py +9 -0
  178. package/plugin/vendor/reflexio/reflexio/models/api_schema/stall_state_schema.py +32 -0
  179. package/plugin/vendor/reflexio/reflexio/models/api_schema/ui/__init__.py +3 -0
  180. package/plugin/vendor/reflexio/reflexio/models/api_schema/ui/converters.py +177 -0
  181. package/plugin/vendor/reflexio/reflexio/models/api_schema/ui/entities.py +129 -0
  182. package/plugin/vendor/reflexio/reflexio/models/api_schema/ui/enums.py +25 -0
  183. package/plugin/vendor/reflexio/reflexio/models/api_schema/validators.py +280 -0
  184. package/plugin/vendor/reflexio/reflexio/models/config_schema.py +908 -0
  185. package/plugin/vendor/reflexio/reflexio/models/py.typed +0 -0
  186. package/plugin/vendor/reflexio/reflexio/server/OVERVIEW.md +90 -0
  187. package/plugin/vendor/reflexio/reflexio/server/README.md +616 -0
  188. package/plugin/vendor/reflexio/reflexio/server/__init__.py +210 -0
  189. package/plugin/vendor/reflexio/reflexio/server/__main__.py +132 -0
  190. package/plugin/vendor/reflexio/reflexio/server/_auth.py +25 -0
  191. package/plugin/vendor/reflexio/reflexio/server/api.py +2714 -0
  192. package/plugin/vendor/reflexio/reflexio/server/api_endpoints/account_api.py +143 -0
  193. package/plugin/vendor/reflexio/reflexio/server/api_endpoints/health_api.py +91 -0
  194. package/plugin/vendor/reflexio/reflexio/server/api_endpoints/pending_tool_call_api.py +572 -0
  195. package/plugin/vendor/reflexio/reflexio/server/api_endpoints/precondition_checks.py +66 -0
  196. package/plugin/vendor/reflexio/reflexio/server/api_endpoints/publisher_api.py +540 -0
  197. package/plugin/vendor/reflexio/reflexio/server/api_endpoints/request_context.py +50 -0
  198. package/plugin/vendor/reflexio/reflexio/server/api_endpoints/stall_state_api.py +100 -0
  199. package/plugin/vendor/reflexio/reflexio/server/cache/__init__.py +15 -0
  200. package/plugin/vendor/reflexio/reflexio/server/cache/reflexio_cache.py +208 -0
  201. package/plugin/vendor/reflexio/reflexio/server/correlation.py +46 -0
  202. package/plugin/vendor/reflexio/reflexio/server/llm/__init__.py +30 -0
  203. package/plugin/vendor/reflexio/reflexio/server/llm/embedding_service.py +110 -0
  204. package/plugin/vendor/reflexio/reflexio/server/llm/image_utils.py +55 -0
  205. package/plugin/vendor/reflexio/reflexio/server/llm/litellm_client.py +1595 -0
  206. package/plugin/vendor/reflexio/reflexio/server/llm/llm_utils.py +112 -0
  207. package/plugin/vendor/reflexio/reflexio/server/llm/model_defaults.py +469 -0
  208. package/plugin/vendor/reflexio/reflexio/server/llm/providers/__init__.py +1 -0
  209. package/plugin/vendor/reflexio/reflexio/server/llm/providers/claude_code_provider.py +1122 -0
  210. package/plugin/vendor/reflexio/reflexio/server/llm/providers/claude_code_stream_parser.py +197 -0
  211. package/plugin/vendor/reflexio/reflexio/server/llm/providers/embedding_service_provider.py +210 -0
  212. package/plugin/vendor/reflexio/reflexio/server/llm/providers/local_embedding_provider.py +213 -0
  213. package/plugin/vendor/reflexio/reflexio/server/llm/providers/nomic_embedding_provider.py +255 -0
  214. package/plugin/vendor/reflexio/reflexio/server/llm/rerank/__init__.py +6 -0
  215. package/plugin/vendor/reflexio/reflexio/server/llm/rerank/cross_encoder_reranker.py +177 -0
  216. package/plugin/vendor/reflexio/reflexio/server/llm/rerank/llm_reranker.py +148 -0
  217. package/plugin/vendor/reflexio/reflexio/server/llm/tools.py +699 -0
  218. package/plugin/vendor/reflexio/reflexio/server/operation_limiter.py +179 -0
  219. package/plugin/vendor/reflexio/reflexio/server/prompt/__init__.py +0 -0
  220. package/plugin/vendor/reflexio/reflexio/server/prompt/_dispatchers.py +54 -0
  221. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/README.md +121 -0
  222. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/agent_success_evaluation/v1.0.0.prompt.md +58 -0
  223. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/agent_success_evaluation_with_comparison/v1.0.0.prompt.md +76 -0
  224. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/answer_synthesis/v1.5.2.prompt.md +88 -0
  225. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/compress_session_for_query/v1.3.0.prompt.md +31 -0
  226. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/document_expansion/v1.0.0.prompt.md +20 -0
  227. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/memory_reflection/v1.0.0.prompt.md +53 -0
  228. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/memory_reflection/v1.1.0.prompt.md +57 -0
  229. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/memory_reflection/v1.2.0.prompt.md +68 -0
  230. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/memory_reflection/v1.3.0.prompt.md +70 -0
  231. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/memory_reflection/v1.4.0.prompt.md +77 -0
  232. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/memory_reflection/v1.5.0.prompt.md +82 -0
  233. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/memory_reflection/v1.6.0.prompt.md +83 -0
  234. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_aggregation/v2.1.0.prompt.md +193 -0
  235. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_aggregation/v2.2.0.prompt.md +206 -0
  236. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v1.0.0-deprecated.prompt.md +66 -0
  237. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v1.0.0.prompt.md +43 -0
  238. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v1.1.0.prompt.md +46 -0
  239. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v2.0.0-deprecated.prompt.md +64 -0
  240. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v2.0.0.prompt.md +39 -0
  241. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v2.1.0.prompt.md +39 -0
  242. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v2.2.0.prompt.md +47 -0
  243. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v2.3.0.prompt.md +58 -0
  244. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context/v4.0.2.prompt.md +254 -0
  245. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context/v4.1.0.prompt.md +274 -0
  246. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context/v4.2.0.prompt.md +279 -0
  247. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context_expert/v1.0.0.prompt.md +73 -0
  248. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context_expert/v2.0.0.prompt.md +86 -0
  249. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context_expert/v3.0.0.prompt.md +97 -0
  250. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context_expert/v3.1.0.prompt.md +119 -0
  251. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context_expert/v3.2.0.prompt.md +123 -0
  252. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context_expert/v3.3.0.prompt.md +127 -0
  253. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_main/v1.0.0.prompt.md +14 -0
  254. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_main/v1.1.0.prompt.md +24 -0
  255. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_main/v1.2.0.prompt.md +29 -0
  256. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_main_expert/v1.0.0.prompt.md +11 -0
  257. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_main_expert/v1.1.0.prompt.md +21 -0
  258. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_main_expert/v1.2.0.prompt.md +25 -0
  259. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_optimizer_judge/v1.0.0.prompt.md +37 -0
  260. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_optimizer_judge/v1.1.0.prompt.md +40 -0
  261. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_optimizer_judge/v1.2.0.prompt.md +36 -0
  262. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_should_generate/v1.0.0.prompt.md +45 -0
  263. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_should_generate/v2.0.0.prompt.md +81 -0
  264. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_should_generate/v3.0.0.prompt.md +80 -0
  265. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_should_generate_expert/v1.0.0.prompt.md +34 -0
  266. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/profile_deduplication/v1.0.0.prompt.md +116 -0
  267. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/profile_should_generate/v1.0.0.prompt.md +33 -0
  268. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/profile_should_generate_override/v1.0.0.prompt.md +16 -0
  269. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/profile_update_instruction_start/v1.0.0.prompt.md +140 -0
  270. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/profile_update_instruction_start/v1.1.0.prompt.md +160 -0
  271. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/profile_update_main/v1.0.0.prompt.md +14 -0
  272. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/query_reformulation/v1.0.0.prompt.md +19 -0
  273. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/rerank_relevance/v1.1.0.prompt.md +44 -0
  274. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/shadow_comparison/v1.0.0.prompt.md +43 -0
  275. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/shadow_content_evaluation/v1.0.0.prompt.md +33 -0
  276. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_evaluation/prompt_evaluation_dataset/feedback_extraction_main_v1.jsonl +10 -0
  277. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_evaluation/prompt_evaluation_dataset/profile_update_main_v1.jsonl +10 -0
  278. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_manager.py +280 -0
  279. package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_schema.py +11 -0
  280. package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/_eval_health.py +131 -0
  281. package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/agent_success_evaluation_constants.py +60 -0
  282. package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/agent_success_evaluation_service.py +228 -0
  283. package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/agent_success_evaluation_utils.py +87 -0
  284. package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/agent_success_evaluator.py +372 -0
  285. package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/delayed_group_evaluator.py +156 -0
  286. package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/group_evaluation_runner.py +340 -0
  287. package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/regen_jobs.py +471 -0
  288. package/plugin/vendor/reflexio/reflexio/server/services/base_generation_service.py +1626 -0
  289. package/plugin/vendor/reflexio/reflexio/server/services/braintrust/__init__.py +0 -0
  290. package/plugin/vendor/reflexio/reflexio/server/services/braintrust/_cron.py +196 -0
  291. package/plugin/vendor/reflexio/reflexio/server/services/braintrust/_encryption.py +101 -0
  292. package/plugin/vendor/reflexio/reflexio/server/services/braintrust/client.py +167 -0
  293. package/plugin/vendor/reflexio/reflexio/server/services/braintrust/service.py +281 -0
  294. package/plugin/vendor/reflexio/reflexio/server/services/configurator/base_configurator.py +179 -0
  295. package/plugin/vendor/reflexio/reflexio/server/services/configurator/config_storage.py +62 -0
  296. package/plugin/vendor/reflexio/reflexio/server/services/configurator/configurator.py +87 -0
  297. package/plugin/vendor/reflexio/reflexio/server/services/configurator/local_file_config_storage.py +187 -0
  298. package/plugin/vendor/reflexio/reflexio/server/services/configurator/test_config_storage.py +162 -0
  299. package/plugin/vendor/reflexio/reflexio/server/services/deduplication_utils.py +112 -0
  300. package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/__init__.py +0 -0
  301. package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/distribution.py +33 -0
  302. package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/eval_sampler.py +126 -0
  303. package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/group_aggregation.py +192 -0
  304. package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/hero_state.py +75 -0
  305. package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/rule_attribution.py +97 -0
  306. package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/service.py +515 -0
  307. package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/shadow_aggregation.py +90 -0
  308. package/plugin/vendor/reflexio/reflexio/server/services/extraction/__init__.py +0 -0
  309. package/plugin/vendor/reflexio/reflexio/server/services/extraction/agent_run_records.py +91 -0
  310. package/plugin/vendor/reflexio/reflexio/server/services/extraction/invariants.py +303 -0
  311. package/plugin/vendor/reflexio/reflexio/server/services/extraction/outcome.py +25 -0
  312. package/plugin/vendor/reflexio/reflexio/server/services/extraction/pending_tool_call_dispatch.py +351 -0
  313. package/plugin/vendor/reflexio/reflexio/server/services/extraction/plan.py +138 -0
  314. package/plugin/vendor/reflexio/reflexio/server/services/extraction/prior_answer_search.py +217 -0
  315. package/plugin/vendor/reflexio/reflexio/server/services/extraction/resumable_agent.py +468 -0
  316. package/plugin/vendor/reflexio/reflexio/server/services/extraction/resume_scheduler.py +171 -0
  317. package/plugin/vendor/reflexio/reflexio/server/services/extraction/resume_worker.py +777 -0
  318. package/plugin/vendor/reflexio/reflexio/server/services/extraction/tools.py +1125 -0
  319. package/plugin/vendor/reflexio/reflexio/server/services/extractor_config_utils.py +91 -0
  320. package/plugin/vendor/reflexio/reflexio/server/services/extractor_interaction_utils.py +251 -0
  321. package/plugin/vendor/reflexio/reflexio/server/services/generation_service.py +689 -0
  322. package/plugin/vendor/reflexio/reflexio/server/services/operation_state_utils.py +835 -0
  323. package/plugin/vendor/reflexio/reflexio/server/services/playbook/README.md +89 -0
  324. package/plugin/vendor/reflexio/reflexio/server/services/playbook/playbook_aggregator.py +1388 -0
  325. package/plugin/vendor/reflexio/reflexio/server/services/playbook/playbook_consolidator.py +960 -0
  326. package/plugin/vendor/reflexio/reflexio/server/services/playbook/playbook_extractor.py +436 -0
  327. package/plugin/vendor/reflexio/reflexio/server/services/playbook/playbook_generation_service.py +808 -0
  328. package/plugin/vendor/reflexio/reflexio/server/services/playbook/playbook_service_constants.py +28 -0
  329. package/plugin/vendor/reflexio/reflexio/server/services/playbook/playbook_service_utils.py +362 -0
  330. package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/__init__.py +24 -0
  331. package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/assistant_webhook.py +246 -0
  332. package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/gepa_adapter.py +291 -0
  333. package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/judge.py +97 -0
  334. package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/models.py +96 -0
  335. package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/optimizer.py +645 -0
  336. package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/rollout.py +35 -0
  337. package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/scenario_resolver.py +93 -0
  338. package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/scheduler.py +174 -0
  339. package/plugin/vendor/reflexio/reflexio/server/services/pre_retrieval/__init__.py +26 -0
  340. package/plugin/vendor/reflexio/reflexio/server/services/pre_retrieval/_document_expander.py +179 -0
  341. package/plugin/vendor/reflexio/reflexio/server/services/pre_retrieval/_query_reformulator.py +297 -0
  342. package/plugin/vendor/reflexio/reflexio/server/services/profile/profile_deduplicator.py +741 -0
  343. package/plugin/vendor/reflexio/reflexio/server/services/profile/profile_extractor.py +462 -0
  344. package/plugin/vendor/reflexio/reflexio/server/services/profile/profile_generation_service.py +734 -0
  345. package/plugin/vendor/reflexio/reflexio/server/services/profile/profile_generation_service_utils.py +290 -0
  346. package/plugin/vendor/reflexio/reflexio/server/services/reflection/__init__.py +17 -0
  347. package/plugin/vendor/reflexio/reflexio/server/services/reflection/reflection_extractor.py +247 -0
  348. package/plugin/vendor/reflexio/reflexio/server/services/reflection/reflection_service.py +800 -0
  349. package/plugin/vendor/reflexio/reflexio/server/services/reflection/reflection_service_utils.py +146 -0
  350. package/plugin/vendor/reflexio/reflexio/server/services/retrieval/__init__.py +0 -0
  351. package/plugin/vendor/reflexio/reflexio/server/services/retrieval/relevance_floor.py +70 -0
  352. package/plugin/vendor/reflexio/reflexio/server/services/search/__init__.py +0 -0
  353. package/plugin/vendor/reflexio/reflexio/server/services/service_utils.py +671 -0
  354. package/plugin/vendor/reflexio/reflexio/server/services/shadow_comparison/__init__.py +1 -0
  355. package/plugin/vendor/reflexio/reflexio/server/services/shadow_comparison/judge.py +184 -0
  356. package/plugin/vendor/reflexio/reflexio/server/services/shadow_comparison/outcome.py +81 -0
  357. package/plugin/vendor/reflexio/reflexio/server/services/storage/constants.py +2 -0
  358. package/plugin/vendor/reflexio/reflexio/server/services/storage/error.py +11 -0
  359. package/plugin/vendor/reflexio/reflexio/server/services/storage/retention.py +154 -0
  360. package/plugin/vendor/reflexio/reflexio/server/services/storage/retention_mixin.py +155 -0
  361. package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/__init__.py +59 -0
  362. package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_agent_run.py +1253 -0
  363. package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_base.py +1945 -0
  364. package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_extras.py +600 -0
  365. package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_operations.py +346 -0
  366. package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_playbook.py +1378 -0
  367. package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_profiles.py +747 -0
  368. package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_requests.py +263 -0
  369. package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_shadow_verdicts.py +193 -0
  370. package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_share_links.py +166 -0
  371. package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_stall_state.py +217 -0
  372. package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/__init__.py +153 -0
  373. package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_agent_run.py +372 -0
  374. package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_base.py +71 -0
  375. package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_extras.py +235 -0
  376. package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_operations.py +170 -0
  377. package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_playbook.py +677 -0
  378. package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_profiles.py +250 -0
  379. package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_requests.py +154 -0
  380. package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_shadow_verdicts.py +130 -0
  381. package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_share_links.py +93 -0
  382. package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_stall_state.py +76 -0
  383. package/plugin/vendor/reflexio/reflexio/server/services/unified_search_service.py +568 -0
  384. package/plugin/vendor/reflexio/reflexio/server/site_var/README.md +77 -0
  385. package/plugin/vendor/reflexio/reflexio/server/site_var/feature_flags.py +116 -0
  386. package/plugin/vendor/reflexio/reflexio/server/site_var/site_var_manager.py +263 -0
  387. package/plugin/vendor/reflexio/reflexio/server/site_var/site_var_sources/feature_flags.json +13 -0
  388. package/plugin/vendor/reflexio/reflexio/server/site_var/site_var_sources/llm_model_setting.json +7 -0
  389. package/plugin/vendor/reflexio/reflexio/server/tracing.py +158 -0
  390. package/plugin/vendor/reflexio/reflexio/server/usage_metrics.py +113 -0
  391. package/plugin/vendor/reflexio/reflexio/server/uvicorn_logging.py +76 -0
  392. package/plugin/vendor/reflexio/reflexio/test_support/__init__.py +1 -0
  393. package/plugin/vendor/reflexio/reflexio/test_support/llm_fixtures.py +62 -0
  394. package/plugin/vendor/reflexio/reflexio/test_support/llm_mock.py +242 -0
  395. package/plugin/vendor/reflexio/reflexio/test_support/llm_model_registry.py +129 -0
  396. package/plugin/vendor/reflexio/reflexio/test_support/skip_decorators.py +43 -0
@@ -0,0 +1,1103 @@
1
+ from __future__ import annotations
2
+
3
+ from datetime import UTC, datetime
4
+ from typing import Any, Literal, Self
5
+
6
+ from pydantic import BaseModel, Field, field_validator, model_validator
7
+
8
+ from reflexio.defaults import DEFAULT_AGENT_VERSION
9
+
10
+ from ..common import (
11
+ NEVER_EXPIRES_TIMESTAMP,
12
+ BlockingIssue,
13
+ BlockingIssueKind,
14
+ ToolUsed,
15
+ )
16
+ from ..validators import (
17
+ EmbeddingVector,
18
+ NonEmptyStr,
19
+ TimeRangeValidatorMixin,
20
+ _validate_image_url,
21
+ )
22
+ from .enums import (
23
+ OperationStatus,
24
+ PlaybookStatus,
25
+ ProfileTimeToLive,
26
+ RegularVsShadow,
27
+ Status,
28
+ UserActionType,
29
+ )
30
+
31
+ __all__ = [
32
+ "NEVER_EXPIRES_TIMESTAMP",
33
+ "BlockingIssue",
34
+ "BlockingIssueKind",
35
+ "ToolUsed",
36
+ "Citation",
37
+ "Interaction",
38
+ "Request",
39
+ "UserProfile",
40
+ "UserPlaybook",
41
+ "ProfileChangeLog",
42
+ "AgentPlaybook",
43
+ "AgentSuccessEvaluationResult",
44
+ "DeleteUserProfileRequest",
45
+ "DeleteUserProfileResponse",
46
+ "DeleteUserInteractionRequest",
47
+ "DeleteUserInteractionResponse",
48
+ "DeleteRequestRequest",
49
+ "DeleteRequestResponse",
50
+ "DeleteSessionRequest",
51
+ "DeleteSessionResponse",
52
+ "DeleteAgentPlaybookRequest",
53
+ "DeleteAgentPlaybookResponse",
54
+ "DeleteUserPlaybookRequest",
55
+ "DeleteUserPlaybookResponse",
56
+ "BulkDeleteResponse",
57
+ "DeleteRequestsByIdsRequest",
58
+ "DeleteProfilesByIdsRequest",
59
+ "DeleteAgentPlaybooksByIdsRequest",
60
+ "DeleteUserPlaybooksByIdsRequest",
61
+ "ClearUserDataRequest",
62
+ "ClearUserDataResponse",
63
+ "InteractionData",
64
+ "PublishUserInteractionRequest",
65
+ "PublishUserInteractionResponse",
66
+ "WhoamiResponse",
67
+ "MyConfigResponse",
68
+ "AddUserPlaybookRequest",
69
+ "AddUserPlaybookResponse",
70
+ "AddAgentPlaybookRequest",
71
+ "AddAgentPlaybookResponse",
72
+ "AddUserProfileRequest",
73
+ "AddUserProfileResponse",
74
+ "ProfileChangeLogResponse",
75
+ "PublicStructuredData",
76
+ "PublicUserPlaybook",
77
+ "PublicAgentPlaybook",
78
+ "user_playbook_to_public",
79
+ "agent_playbook_to_public",
80
+ "PublicGetUserPlaybooksResponse",
81
+ "PublicGetAgentPlaybooksResponse",
82
+ "PublicSearchUserPlaybookResponse",
83
+ "PublicSearchAgentPlaybookResponse",
84
+ "PublicUnifiedSearchResponse",
85
+ "AgentPlaybookSnapshot",
86
+ "AgentPlaybookUpdateEntry",
87
+ "PlaybookAggregationChangeLog",
88
+ "PlaybookAggregationChangeLogResponse",
89
+ "PlaybookOptimizationJob",
90
+ "PlaybookOptimizationCandidate",
91
+ "PlaybookOptimizationEvaluation",
92
+ "PlaybookOptimizationEvent",
93
+ "AgentPlaybookSourceWindow",
94
+ "agent_playbook_to_snapshot",
95
+ "RunPlaybookAggregationRequest",
96
+ "RunPlaybookAggregationResponse",
97
+ "RerunProfileGenerationRequest",
98
+ "RerunProfileGenerationResponse",
99
+ "ManualProfileGenerationRequest",
100
+ "ManualProfileGenerationResponse",
101
+ "ManualPlaybookGenerationRequest",
102
+ "ManualPlaybookGenerationResponse",
103
+ "RerunPlaybookGenerationRequest",
104
+ "RerunPlaybookGenerationResponse",
105
+ "UpgradeProfilesRequest",
106
+ "UpgradeProfilesResponse",
107
+ "DowngradeProfilesRequest",
108
+ "DowngradeProfilesResponse",
109
+ "UpgradeUserPlaybooksRequest",
110
+ "UpgradeUserPlaybooksResponse",
111
+ "DowngradeUserPlaybooksRequest",
112
+ "DowngradeUserPlaybooksResponse",
113
+ "OperationStatusInfo",
114
+ "GetOperationStatusRequest",
115
+ "GetOperationStatusResponse",
116
+ "CancelOperationRequest",
117
+ "CancelOperationResponse",
118
+ "ShareLink",
119
+ "AdminInvalidateCacheRequest",
120
+ "AdminInvalidateCacheResponse",
121
+ ]
122
+
123
+ # ===============================
124
+ # Data Models
125
+ # ===============================
126
+
127
+
128
+ class Citation(BaseModel):
129
+ """A playbook or profile item the agent cited as influential.
130
+
131
+ Carried inline on an Assistant ``InteractionData`` row to mark
132
+ which previously-injected playbook rule or user-profile row
133
+ materially shaped that response. The server uses these to drive
134
+ reflection (does the cited rule still look right after seeing how
135
+ it was applied?).
136
+
137
+ Attributes:
138
+ kind (Literal["playbook", "profile"]): Which kind of cited
139
+ item this references.
140
+ real_id (str): Stable storage id — ``user_playbook_id`` for
141
+ playbooks, ``profile_id`` for profiles.
142
+ tag (str): Injection-time rank tag (e.g. ``"r1-301"``,
143
+ ``"p1-0f37"``). Per-injection, not stable across sessions;
144
+ kept as a debug aid.
145
+ title (str): Short human-readable label for logs and UI.
146
+ """
147
+
148
+ kind: Literal["playbook", "profile"]
149
+ real_id: str
150
+ tag: str = ""
151
+ title: str = ""
152
+
153
+
154
+ # information about the user interaction sent by the client
155
+ class Interaction(BaseModel):
156
+ interaction_id: int = 0 # 0 = placeholder for DB auto-increment
157
+ user_id: str
158
+ request_id: str
159
+ created_at: int = Field(default_factory=lambda: int(datetime.now(UTC).timestamp()))
160
+ role: str = "User"
161
+ content: str = ""
162
+ user_action: UserActionType = UserActionType.NONE
163
+ user_action_description: str = ""
164
+ interacted_image_url: str = ""
165
+ image_encoding: str = "" # base64 encoded image
166
+ shadow_content: str = ""
167
+ expert_content: str = ""
168
+ tools_used: list[ToolUsed] = Field(default_factory=list)
169
+ citations: list[Citation] = Field(default_factory=list)
170
+ embedding: EmbeddingVector = []
171
+
172
+ @field_validator("interacted_image_url", mode="after")
173
+ @classmethod
174
+ def validate_image_url(cls, v: str) -> str:
175
+ return _validate_image_url(v)
176
+
177
+
178
+ class Request(BaseModel):
179
+ """A user-issued request that begins or continues a session.
180
+
181
+ A Request is the unit of work the agent reacts to. Multiple Requests
182
+ share a ``session_id`` to form a multi-turn session. The optional
183
+ ``metadata`` dict carries per-request key/value annotations stamped by
184
+ customer integration code — distinct from ``playbook_metadata`` (a
185
+ JSON-encoded string) used by ``Playbook``-family entities elsewhere in
186
+ this module.
187
+
188
+ Attributes:
189
+ request_id (str): Unique identifier for this request.
190
+ user_id (str): Owner of the request.
191
+ created_at (int): Unix epoch seconds at request creation. Defaults
192
+ to the current UTC time.
193
+ source (str): Free-form origin tag (integration name, etc.).
194
+ agent_version (str): The agent version that handled this request.
195
+ session_id (str | None): Session this request belongs to, or None
196
+ if the request is not part of a multi-turn session.
197
+ metadata (dict[str, Any]): Free-form per-request annotations.
198
+ Always a dict — never None. Conventional keys:
199
+
200
+ - ``reflexio_retrieval_enabled`` (bool): F2 group-by signal;
201
+ customer integration code stamps this to indicate whether
202
+ Reflexio retrieval was active for the session. Read by the
203
+ ``/api/get_evaluation_overview`` aggregator from the FIRST
204
+ request of each session for sticky group assignment.
205
+
206
+ Distinct from ``playbook_metadata`` on ``Playbook``-family
207
+ entities (which is a JSON-encoded string, not a dict).
208
+ On-the-wire serialization assumes JSON-encodable values;
209
+ non-JSON values like ``datetime`` or ``set`` will fail at
210
+ the storage / API boundary.
211
+ """
212
+
213
+ request_id: str
214
+ user_id: str
215
+ created_at: int = Field(default_factory=lambda: int(datetime.now(UTC).timestamp()))
216
+ source: str = ""
217
+ agent_version: str = ""
218
+ session_id: str | None = None
219
+ metadata: dict[str, Any] = Field(default_factory=dict)
220
+
221
+
222
+ # information about the user profile generated from the user interaction
223
+ # output of the profile generation service send back to the client
224
+ class UserProfile(BaseModel):
225
+ profile_id: str
226
+ user_id: str
227
+ content: str
228
+ last_modified_timestamp: int
229
+ generated_from_request_id: str
230
+ profile_time_to_live: ProfileTimeToLive = ProfileTimeToLive.INFINITY
231
+ # this is the expiration date calculated based on last modified timestamp and profile time to live instead of generated timestamp
232
+ expiration_timestamp: int = NEVER_EXPIRES_TIMESTAMP
233
+ custom_features: dict | None = None
234
+ source: str | None = None
235
+ status: Status | None = None # indicates the status of the profile
236
+ extractor_names: list[str] | None = None # Retained provenance data column (merged on dedup); new profiles write None.
237
+ expanded_terms: str | None = None
238
+ embedding: EmbeddingVector = []
239
+ source_span: str | None = None
240
+ notes: str | None = None
241
+ reader_angle: str | None = None
242
+
243
+
244
+ # user playbook for agents
245
+ class UserPlaybook(BaseModel):
246
+ user_playbook_id: int = 0
247
+ user_id: str | None = None # optional for backward compatibility
248
+ agent_version: str
249
+ request_id: str
250
+ playbook_name: str = ""
251
+ created_at: int = Field(default_factory=lambda: int(datetime.now(UTC).timestamp()))
252
+ content: str = ""
253
+ trigger: str | None = None
254
+ rationale: str | None = None
255
+ blocking_issue: BlockingIssue | None = None
256
+ status: Status | None = (
257
+ None # Status.PENDING (from rerun), None (current), Status.ARCHIVED (old)
258
+ )
259
+ source: str | None = None # source of the interaction that generated this playbook
260
+ source_interaction_ids: list[int] = Field(default_factory=list)
261
+ expanded_terms: str | None = None
262
+ embedding: EmbeddingVector = []
263
+ source_span: str | None = None
264
+ notes: str | None = None
265
+ reader_angle: str | None = None
266
+
267
+
268
+ class ProfileChangeLog(BaseModel):
269
+ id: int
270
+ user_id: str
271
+ request_id: str
272
+ created_at: int = Field(default_factory=lambda: int(datetime.now(UTC).timestamp()))
273
+ added_profiles: list[UserProfile]
274
+ removed_profiles: list[UserProfile]
275
+ mentioned_profiles: list[UserProfile]
276
+
277
+
278
+ class AgentPlaybook(BaseModel):
279
+ agent_playbook_id: int = 0
280
+ playbook_name: str = ""
281
+ agent_version: str
282
+ created_at: int = Field(default_factory=lambda: int(datetime.now(UTC).timestamp()))
283
+ content: str
284
+ trigger: str | None = None
285
+ rationale: str | None = None
286
+ blocking_issue: BlockingIssue | None = None
287
+ playbook_status: PlaybookStatus = PlaybookStatus.PENDING
288
+ playbook_metadata: str = ""
289
+ expanded_terms: str | None = None
290
+ embedding: EmbeddingVector = []
291
+ status: Status | None = (
292
+ None # used for tracking intermediate states during playbook aggregation. Status.ARCHIVED for playbooks during aggregation process, None for current playbooks
293
+ )
294
+
295
+
296
+ class PlaybookOptimizationJob(BaseModel):
297
+ """One end-to-end optimizer run for a single playbook target.
298
+
299
+ Lifecycle: ``pending`` → ``running`` → ``completed`` | ``failed`` |
300
+ ``skipped``. ``best_candidate_id`` and ``successor_target_id`` are set
301
+ when the run produces a winner or commits a successor playbook.
302
+ """
303
+
304
+ job_id: int = 0
305
+ target_kind: Literal["agent_playbook", "user_playbook"]
306
+ target_id: int
307
+ status: Literal["pending", "running", "completed", "skipped", "failed"] = "pending"
308
+ best_candidate_id: int | None = None
309
+ successor_target_id: int | None = None
310
+ decision_reason: str = ""
311
+ metadata_json: str = "{}"
312
+ created_at: int = Field(default_factory=lambda: int(datetime.now(UTC).timestamp()))
313
+ updated_at: int = Field(default_factory=lambda: int(datetime.now(UTC).timestamp()))
314
+
315
+
316
+ class PlaybookOptimizationCandidate(BaseModel):
317
+ """A playbook content variant proposed by GEPA during a job.
318
+
319
+ Multiple proposals with identical content collapse to one row (deduped
320
+ by ``content`` inside the GEPA adapter). ``aggregate_score`` and
321
+ ``is_winner`` are populated only for the run's chosen winner.
322
+ """
323
+
324
+ candidate_id: int = 0
325
+ job_id: int
326
+ candidate_index: int = 0
327
+ content: str
328
+ parent_candidate_ids: list[int] = Field(default_factory=list)
329
+ aggregate_score: float | None = None
330
+ is_winner: bool = False
331
+ created_at: int = Field(default_factory=lambda: int(datetime.now(UTC).timestamp()))
332
+
333
+
334
+ class PlaybookOptimizationEvaluation(BaseModel):
335
+ """Pairwise judgement of one candidate vs. the incumbent on one window.
336
+
337
+ Both rollouts are stored as JSON for offline reproducibility.
338
+ ``verdict='aborted'`` means the assistant backend failed and the row
339
+ carries no useful signal — the optimizer treats any aborted evaluation
340
+ as fatal for the run.
341
+ """
342
+
343
+ evaluation_id: int = 0
344
+ job_id: int
345
+ candidate_id: int
346
+ target_kind: Literal["agent_playbook", "user_playbook"]
347
+ target_id: int
348
+ scenario_user_playbook_id: int | None = None
349
+ source_interaction_ids: list[int] = Field(default_factory=list)
350
+ score: float = 0.0
351
+ verdict: Literal["candidate", "incumbent", "tie", "aborted"] = "tie"
352
+ likert: int = Field(default=0, ge=0, le=5)
353
+ rationale: str = ""
354
+ asi_json: str = "{}"
355
+ incumbent_rollout_json: str = "[]"
356
+ candidate_rollout_json: str = "[]"
357
+ created_at: int = Field(default_factory=lambda: int(datetime.now(UTC).timestamp()))
358
+
359
+
360
+ class PlaybookOptimizationEvent(BaseModel):
361
+ """One GEPA callback (``on_*``) event captured for offline inspection.
362
+
363
+ The optimizer's ``_GEPAStorageCallback`` forwards every dispatched
364
+ callback into a row of this type. ``event_type`` is the callback name
365
+ minus the ``on_`` prefix; ``payload_json`` is a depth-bounded
366
+ serialization of the callback's argument.
367
+ """
368
+
369
+ event_id: int = 0
370
+ job_id: int
371
+ event_type: str
372
+ payload_json: str = "{}"
373
+ created_at: int = Field(default_factory=lambda: int(datetime.now(UTC).timestamp()))
374
+
375
+
376
+ class AgentPlaybookSourceWindow(BaseModel):
377
+ """Replayable source window snapshotted when an agent playbook is generated."""
378
+
379
+ user_playbook_id: int
380
+ source_interaction_ids: list[int] = Field(default_factory=list)
381
+
382
+
383
+ class AgentSuccessEvaluationResult(BaseModel):
384
+ result_id: int = 0
385
+ agent_version: str
386
+ session_id: str
387
+ is_success: bool
388
+ failure_type: str | None = None
389
+ failure_reason: str | None = None
390
+ evaluation_name: str | None = None
391
+ created_at: int = Field(default_factory=lambda: int(datetime.now(UTC).timestamp()))
392
+ regular_vs_shadow: RegularVsShadow | None = None
393
+ number_of_correction_per_session: int = 0
394
+ user_turns_to_resolution: int | None = None
395
+ is_escalated: bool = False
396
+ embedding: EmbeddingVector = []
397
+
398
+
399
+ class ShareLink(BaseModel):
400
+ """A shareable public link that maps a token to a resource within an org.
401
+
402
+ Args:
403
+ id (int): Primary key assigned by the storage layer.
404
+ org_id (str): The organization that owns the share link.
405
+ token (str): The share token (unique). Format: shr_<org_id_b64>.<random>.
406
+ resource_type (str): One of "profile", "request", "session", "user_playbook", "agent_playbook".
407
+ resource_id (str): The ID of the resource being shared.
408
+ created_at (int | None): Unix timestamp of creation.
409
+ expires_at (int | None): Optional Unix timestamp of expiration. None means never expires.
410
+ created_by_email (str | None): Optional email of the user who created the link.
411
+ """
412
+
413
+ id: int
414
+ org_id: str
415
+ token: str
416
+ resource_type: str
417
+ resource_id: str
418
+ created_at: int | None = None
419
+ expires_at: int | None = None
420
+ created_by_email: str | None = None
421
+
422
+
423
+ # ===============================
424
+ # Request Models
425
+ # ===============================
426
+
427
+
428
+ # delete user profile request
429
+ class DeleteUserProfileRequest(BaseModel):
430
+ user_id: NonEmptyStr
431
+ profile_id: str = ""
432
+ search_query: str = ""
433
+
434
+
435
+ # delete user profile response
436
+ class DeleteUserProfileResponse(BaseModel):
437
+ success: bool
438
+ message: str = ""
439
+
440
+
441
+ # delete user interaction request
442
+ class DeleteUserInteractionRequest(BaseModel):
443
+ user_id: NonEmptyStr
444
+ interaction_id: int = Field(gt=0)
445
+
446
+
447
+ # delete user interaction response
448
+ class DeleteUserInteractionResponse(BaseModel):
449
+ success: bool
450
+ message: str = ""
451
+
452
+
453
+ # delete request request
454
+ class DeleteRequestRequest(BaseModel):
455
+ request_id: NonEmptyStr
456
+
457
+
458
+ # delete request response
459
+ class DeleteRequestResponse(BaseModel):
460
+ success: bool
461
+ message: str = ""
462
+
463
+
464
+ # delete session request
465
+ class DeleteSessionRequest(BaseModel):
466
+ session_id: NonEmptyStr
467
+
468
+
469
+ # delete session response
470
+ class DeleteSessionResponse(BaseModel):
471
+ success: bool
472
+ message: str = ""
473
+ deleted_requests_count: int = 0
474
+
475
+
476
+ # delete agent playbook request
477
+ class DeleteAgentPlaybookRequest(BaseModel):
478
+ agent_playbook_id: int = Field(gt=0)
479
+
480
+
481
+ # delete agent playbook response
482
+ class DeleteAgentPlaybookResponse(BaseModel):
483
+ success: bool
484
+ message: str = ""
485
+
486
+
487
+ # delete user playbook request
488
+ class DeleteUserPlaybookRequest(BaseModel):
489
+ user_playbook_id: int = Field(gt=0)
490
+
491
+
492
+ # delete user playbook response
493
+ class DeleteUserPlaybookResponse(BaseModel):
494
+ success: bool
495
+ message: str = ""
496
+
497
+
498
+ class BulkDeleteResponse(BaseModel):
499
+ success: bool
500
+ deleted_count: int = 0
501
+ message: str = ""
502
+
503
+
504
+ class DeleteRequestsByIdsRequest(BaseModel):
505
+ request_ids: list[str] = Field(min_length=1)
506
+
507
+
508
+ class DeleteProfilesByIdsRequest(BaseModel):
509
+ profile_ids: list[str] = Field(min_length=1)
510
+
511
+
512
+ class DeleteAgentPlaybooksByIdsRequest(BaseModel):
513
+ agent_playbook_ids: list[int] = Field(min_length=1)
514
+
515
+
516
+ class DeleteUserPlaybooksByIdsRequest(BaseModel):
517
+ user_playbook_ids: list[int] = Field(min_length=1)
518
+
519
+
520
+ # Clear all data scoped to a single user_id (interactions, requests, user
521
+ # playbooks, profiles). Used by paired-protocol harnesses (e.g. SWE-bench) to
522
+ # isolate per-task data on a shared storage backend without nuking sibling
523
+ # tasks' rows. Intentionally does NOT touch agent_playbooks — they are the
524
+ # cross-project rollup of skills and have no user_id column.
525
+ class ClearUserDataRequest(BaseModel):
526
+ user_id: NonEmptyStr
527
+
528
+
529
+ class ClearUserDataResponse(BaseModel):
530
+ success: bool
531
+ deleted_counts: dict[str, int] = Field(default_factory=dict)
532
+ message: str | None = None
533
+
534
+
535
+ # user provided interaction data from the request
536
+ class InteractionData(BaseModel):
537
+ created_at: int = Field(default_factory=lambda: int(datetime.now(UTC).timestamp()))
538
+ role: str = "User"
539
+ content: str = ""
540
+ shadow_content: str = ""
541
+ expert_content: str = ""
542
+ user_action: UserActionType = UserActionType.NONE
543
+ user_action_description: str = ""
544
+ interacted_image_url: str = ""
545
+ image_encoding: str = "" # base64 encoded image
546
+ tools_used: list[ToolUsed] = Field(default_factory=list)
547
+ citations: list[Citation] = Field(default_factory=list)
548
+
549
+ @field_validator("interacted_image_url", mode="after")
550
+ @classmethod
551
+ def validate_image_url(cls, v: str) -> str:
552
+ return _validate_image_url(v)
553
+
554
+
555
+ # publish user interaction request
556
+ class PublishUserInteractionRequest(BaseModel):
557
+ user_id: NonEmptyStr
558
+ interaction_data_list: list[InteractionData] = Field(min_length=1)
559
+ source: str = ""
560
+ agent_version: str = (
561
+ "" # this is used for aggregating interactions for generating agent playbooks
562
+ )
563
+ session_id: str | None = None # used for grouping requests together
564
+ skip_aggregation: bool = (
565
+ False # when True, extract profiles/playbooks but skip aggregation
566
+ )
567
+ force_extraction: bool = False # when True, bypass all extraction gates (stride_size, cheap pre-filter, LLM should_run) and always run extractors
568
+ override_learning_stall: bool = False # when True, run extraction even if a provider auth/billing stall is recorded
569
+ metadata: dict[str, Any] = Field(default_factory=dict)
570
+ """Per-request annotations stamped by customer integration code.
571
+
572
+ Mirrors ``Request.metadata`` — the publish path copies this dict
573
+ onto the ``Request`` row it creates so the eval pipeline (and the
574
+ F2 sticky-group aggregator in particular) can read it back from
575
+ the first request of each session.
576
+
577
+ Conventional keys:
578
+ - ``reflexio_retrieval_enabled`` (bool): F2 group assignment signal.
579
+
580
+ Defaults to ``{}`` (never None) for backward compatibility — existing
581
+ callers that don't pass ``metadata`` keep working unchanged.
582
+ """
583
+
584
+
585
+ # publish user interaction response
586
+ class PublishUserInteractionResponse(BaseModel):
587
+ success: bool
588
+ message: str = ""
589
+ warnings: list[str] = Field(default_factory=list)
590
+ # Diagnostics (populated only when wait_for_response=True; None otherwise).
591
+ # Exposed so the CLI can tell users *where* their publish landed.
592
+ request_id: str | None = None
593
+ endpoint_url: str | None = None
594
+ storage_type: str | None = None
595
+ storage_label: str | None = None
596
+ profiles_added: int | None = None
597
+ profiles_updated: int | None = None
598
+ playbooks_added: int | None = None
599
+ playbooks_updated: int | None = None
600
+
601
+
602
+ # whoami response — caller identity + resolved storage routing (masked)
603
+ class WhoamiResponse(BaseModel):
604
+ success: bool
605
+ org_id: str
606
+ storage_type: str | None = None
607
+ storage_label: str | None = None # always masked — never contains raw keys
608
+ storage_configured: bool = False
609
+ message: str = ""
610
+
611
+
612
+ # my_config response — caller's raw storage credentials (token-gated)
613
+ class MyConfigResponse(BaseModel):
614
+ success: bool
615
+ # serialized StorageConfig — may contain secrets
616
+ storage_config: dict[str, Any] | None = None
617
+ storage_type: str | None = None
618
+ message: str = ""
619
+
620
+
621
+ # add user playbook request/response
622
+ class AddUserPlaybookRequest(BaseModel):
623
+ user_playbooks: list[UserPlaybook] = Field(min_length=1)
624
+
625
+ @model_validator(mode="after")
626
+ def check_content_fields(self) -> Self:
627
+ """Ensure each user playbook has content for embedding."""
628
+ for i, rf in enumerate(self.user_playbooks):
629
+ if not any((rf.trigger, rf.content)):
630
+ raise ValueError(
631
+ f"user_playbooks[{i}]: at least one of content "
632
+ "or trigger must be provided"
633
+ )
634
+ return self
635
+
636
+
637
+ class AddUserPlaybookResponse(BaseModel):
638
+ success: bool
639
+ message: str | None = None
640
+ added_count: int = 0
641
+
642
+
643
+ # add agent playbook request/response (for aggregated playbooks)
644
+ class AddAgentPlaybookRequest(BaseModel):
645
+ agent_playbooks: list[AgentPlaybook] = Field(min_length=1)
646
+
647
+
648
+ class AddAgentPlaybookResponse(BaseModel):
649
+ success: bool
650
+ message: str | None = None
651
+ added_count: int = 0
652
+
653
+
654
+ # add user profile request/response (manual profile injection,
655
+ # bypassing the inference pipeline)
656
+ class AddUserProfileRequest(BaseModel):
657
+ user_profiles: list[UserProfile] = Field(min_length=1)
658
+
659
+ @model_validator(mode="after")
660
+ def check_content(self) -> Self:
661
+ """Ensure each profile has non-empty content for embedding."""
662
+ for i, p in enumerate(self.user_profiles):
663
+ if not p.content:
664
+ raise ValueError(
665
+ f"user_profiles[{i}].content is required for embedding"
666
+ )
667
+ return self
668
+
669
+
670
+ class AddUserProfileResponse(BaseModel):
671
+ success: bool
672
+ message: str | None = None
673
+ added_count: int = 0
674
+
675
+
676
+ class ProfileChangeLogResponse(BaseModel):
677
+ success: bool
678
+ profile_change_logs: list[ProfileChangeLog]
679
+
680
+
681
+ class PublicStructuredData(BaseModel):
682
+ """Deprecated: kept for backward compatibility with deprecated Public* models."""
683
+
684
+ trigger: str | None = None
685
+
686
+
687
+ class PublicUserPlaybook(BaseModel):
688
+ """Deprecated: use UserPlaybookView from api_schema.ui instead."""
689
+
690
+ user_playbook_id: int = 0
691
+ user_id: str | None = None
692
+ agent_version: str
693
+ request_id: str
694
+ playbook_name: str = ""
695
+ created_at: int = Field(default_factory=lambda: int(datetime.now(UTC).timestamp()))
696
+ content: str = ""
697
+ trigger: str | None = None
698
+ rationale: str | None = None
699
+ status: Status | None = None
700
+ source: str | None = None
701
+ source_interaction_ids: list[int] = Field(default_factory=list)
702
+
703
+
704
+ class PublicAgentPlaybook(BaseModel):
705
+ """Deprecated: use AgentPlaybookView from api_schema.ui instead."""
706
+
707
+ agent_playbook_id: int = 0
708
+ playbook_name: str = ""
709
+ agent_version: str
710
+ created_at: int = Field(default_factory=lambda: int(datetime.now(UTC).timestamp()))
711
+ content: str
712
+ trigger: str | None = None
713
+ rationale: str | None = None
714
+ playbook_status: PlaybookStatus = PlaybookStatus.PENDING
715
+ playbook_metadata: str = ""
716
+ status: Status | None = None
717
+
718
+
719
+ def user_playbook_to_public(rf: UserPlaybook) -> PublicUserPlaybook:
720
+ """Deprecated: use to_user_playbook_view from api_schema.ui instead."""
721
+ return PublicUserPlaybook(
722
+ user_playbook_id=rf.user_playbook_id,
723
+ user_id=rf.user_id,
724
+ agent_version=rf.agent_version,
725
+ request_id=rf.request_id,
726
+ playbook_name=rf.playbook_name,
727
+ created_at=rf.created_at,
728
+ content=rf.content,
729
+ trigger=rf.trigger,
730
+ rationale=rf.rationale,
731
+ status=rf.status,
732
+ source=rf.source,
733
+ source_interaction_ids=rf.source_interaction_ids,
734
+ )
735
+
736
+
737
+ def agent_playbook_to_public(fb: AgentPlaybook) -> PublicAgentPlaybook:
738
+ """Deprecated: use to_agent_playbook_view from api_schema.ui instead."""
739
+ return PublicAgentPlaybook(
740
+ agent_playbook_id=fb.agent_playbook_id,
741
+ playbook_name=fb.playbook_name,
742
+ agent_version=fb.agent_version,
743
+ created_at=fb.created_at,
744
+ content=fb.content,
745
+ trigger=fb.trigger,
746
+ rationale=fb.rationale,
747
+ playbook_status=fb.playbook_status,
748
+ playbook_metadata=fb.playbook_metadata,
749
+ status=fb.status,
750
+ )
751
+
752
+
753
+ class PublicGetUserPlaybooksResponse(BaseModel):
754
+ """Deprecated: use GetUserPlaybooksViewResponse from api_schema.retriever_schema instead.
755
+
756
+ API response for get_user_playbooks — uses public types.
757
+ """
758
+
759
+ success: bool
760
+ user_playbooks: list[PublicUserPlaybook]
761
+ msg: str | None = None
762
+
763
+
764
+ class PublicGetAgentPlaybooksResponse(BaseModel):
765
+ """Deprecated: use GetAgentPlaybooksViewResponse from api_schema.retriever_schema instead.
766
+
767
+ API response for get_agent_playbooks — uses public types.
768
+ """
769
+
770
+ success: bool
771
+ agent_playbooks: list[PublicAgentPlaybook]
772
+ msg: str | None = None
773
+
774
+
775
+ class PublicSearchUserPlaybookResponse(BaseModel):
776
+ """Deprecated: use SearchUserPlaybooksViewResponse from api_schema.retriever_schema instead.
777
+
778
+ API response for search_user_playbooks — uses public types.
779
+ """
780
+
781
+ success: bool
782
+ user_playbooks: list[PublicUserPlaybook]
783
+ msg: str | None = None
784
+
785
+
786
+ class PublicSearchAgentPlaybookResponse(BaseModel):
787
+ """Deprecated: use SearchAgentPlaybooksViewResponse from api_schema.retriever_schema instead.
788
+
789
+ API response for search_agent_playbooks — uses public types.
790
+ """
791
+
792
+ success: bool
793
+ agent_playbooks: list[PublicAgentPlaybook]
794
+ msg: str | None = None
795
+
796
+
797
+ class PublicUnifiedSearchResponse(BaseModel):
798
+ """Deprecated: use UnifiedSearchViewResponse from api_schema.retriever_schema instead.
799
+
800
+ API response for unified search — uses public types for playbooks.
801
+ """
802
+
803
+ success: bool
804
+ profiles: list[UserProfile] = []
805
+ agent_playbooks: list[PublicAgentPlaybook] = []
806
+ user_playbooks: list[PublicUserPlaybook] = []
807
+ reformulated_query: str | None = None
808
+ msg: str | None = None
809
+
810
+
811
+ class AgentPlaybookSnapshot(BaseModel):
812
+ """Lightweight agent playbook snapshot for change log JSONB payloads (excludes embedding and internal status)."""
813
+
814
+ agent_playbook_id: int = 0
815
+ playbook_name: str = ""
816
+ agent_version: str = ""
817
+ content: str = ""
818
+ trigger: str | None = None
819
+ rationale: str | None = None
820
+ blocking_issue: BlockingIssue | None = None
821
+ playbook_status: PlaybookStatus = PlaybookStatus.PENDING
822
+ playbook_metadata: str = ""
823
+
824
+
825
+ class AgentPlaybookUpdateEntry(BaseModel):
826
+ """Before/after pair for an updated agent playbook."""
827
+
828
+ before: AgentPlaybookSnapshot
829
+ after: AgentPlaybookSnapshot
830
+
831
+
832
+ class PlaybookAggregationChangeLog(BaseModel):
833
+ """Tracks changes from a single playbook aggregation run."""
834
+
835
+ id: int = 0
836
+ created_at: int = Field(default_factory=lambda: int(datetime.now(UTC).timestamp()))
837
+ playbook_name: str
838
+ agent_version: str
839
+ run_mode: Literal["full_archive", "incremental"]
840
+ added_agent_playbooks: list[AgentPlaybookSnapshot] = Field(default_factory=list)
841
+ removed_agent_playbooks: list[AgentPlaybookSnapshot] = Field(default_factory=list)
842
+ updated_agent_playbooks: list[AgentPlaybookUpdateEntry] = Field(
843
+ default_factory=list
844
+ )
845
+
846
+
847
+ class PlaybookAggregationChangeLogResponse(BaseModel):
848
+ success: bool
849
+ change_logs: list[PlaybookAggregationChangeLog]
850
+
851
+
852
+ def agent_playbook_to_snapshot(playbook: AgentPlaybook) -> AgentPlaybookSnapshot:
853
+ """Convert an AgentPlaybook to a lightweight AgentPlaybookSnapshot (excludes embedding and internal status).
854
+
855
+ Args:
856
+ playbook (AgentPlaybook): Full agent playbook object
857
+
858
+ Returns:
859
+ AgentPlaybookSnapshot: Lightweight snapshot for change log storage
860
+ """
861
+ return AgentPlaybookSnapshot(
862
+ agent_playbook_id=playbook.agent_playbook_id,
863
+ playbook_name=playbook.playbook_name,
864
+ agent_version=playbook.agent_version,
865
+ content=playbook.content,
866
+ trigger=playbook.trigger,
867
+ rationale=playbook.rationale,
868
+ blocking_issue=playbook.blocking_issue,
869
+ playbook_status=playbook.playbook_status,
870
+ playbook_metadata=playbook.playbook_metadata,
871
+ )
872
+
873
+
874
+ class RunPlaybookAggregationRequest(BaseModel):
875
+ agent_version: str = DEFAULT_AGENT_VERSION
876
+ playbook_name: NonEmptyStr = "playbook"
877
+
878
+ @field_validator("agent_version")
879
+ @classmethod
880
+ def resolve_version(cls, v: str) -> str:
881
+ return v or DEFAULT_AGENT_VERSION
882
+
883
+
884
+ class RunPlaybookAggregationResponse(BaseModel):
885
+ success: bool
886
+ message: str = ""
887
+
888
+
889
+ class RerunProfileGenerationRequest(BaseModel):
890
+ user_id: str | None = None
891
+ start_time: datetime | None = None
892
+ end_time: datetime | None = None
893
+ source: str | None = None
894
+ extractor_names: list[str] | None = None # Deprecated compatibility field; ignored for selection.
895
+
896
+ @model_validator(mode="after")
897
+ def check_time_range(self) -> Self:
898
+ """Validate that end_time is after start_time."""
899
+ TimeRangeValidatorMixin.validate_time_range(self.start_time, self.end_time)
900
+ return self
901
+
902
+
903
+ class RerunProfileGenerationResponse(BaseModel):
904
+ success: bool
905
+ msg: str | None = None
906
+ profiles_generated: int | None = None
907
+ operation_id: str = "rerun_profile_generation"
908
+
909
+
910
+ class ManualProfileGenerationRequest(BaseModel):
911
+ """Request for manual trigger of regular profile generation.
912
+
913
+ Uses window-sized interactions (from config) instead of all interactions.
914
+ Outputs profiles with CURRENT status (not PENDING like rerun).
915
+ """
916
+
917
+ user_id: str | None = None
918
+ source: str | None = None
919
+ extractor_names: list[str] | None = None
920
+
921
+
922
+ class ManualProfileGenerationResponse(BaseModel):
923
+ """Response for manual profile generation."""
924
+
925
+ success: bool
926
+ msg: str | None = None
927
+ profiles_generated: int | None = None
928
+
929
+
930
+ class ManualPlaybookGenerationRequest(BaseModel):
931
+ """Request for manual trigger of regular playbook generation.
932
+
933
+ Uses window-sized interactions (from config) instead of all interactions.
934
+ Outputs playbooks with CURRENT status (not PENDING like rerun).
935
+ """
936
+
937
+ agent_version: str = DEFAULT_AGENT_VERSION
938
+ source: str | None = None
939
+ playbook_name: str | None = None # Deprecated compatibility field; ignored for selection.
940
+
941
+ @field_validator("agent_version")
942
+ @classmethod
943
+ def resolve_version(cls, v: str) -> str:
944
+ return v or DEFAULT_AGENT_VERSION
945
+
946
+
947
+ class ManualPlaybookGenerationResponse(BaseModel):
948
+ """Response for manual playbook generation."""
949
+
950
+ success: bool
951
+ msg: str | None = None
952
+ playbooks_generated: int | None = None
953
+
954
+
955
+ class RerunPlaybookGenerationRequest(BaseModel):
956
+ agent_version: str = DEFAULT_AGENT_VERSION
957
+ start_time: datetime | None = None
958
+ end_time: datetime | None = None
959
+ playbook_name: str | None = None # Deprecated compatibility field; ignored for selection.
960
+ source: str | None = None
961
+
962
+ @field_validator("agent_version")
963
+ @classmethod
964
+ def resolve_version(cls, v: str) -> str:
965
+ return v or DEFAULT_AGENT_VERSION
966
+
967
+ @model_validator(mode="after")
968
+ def check_time_range(self) -> Self:
969
+ """Validate that end_time is after start_time."""
970
+ TimeRangeValidatorMixin.validate_time_range(self.start_time, self.end_time)
971
+ return self
972
+
973
+
974
+ class RerunPlaybookGenerationResponse(BaseModel):
975
+ success: bool
976
+ msg: str | None = None
977
+ playbooks_generated: int | None = None
978
+ operation_id: str = "rerun_playbook_generation"
979
+
980
+
981
+ class UpgradeProfilesRequest(BaseModel):
982
+ user_id: str | None = None # None means "all users"
983
+ profile_ids: list[str] | None = None
984
+ only_affected_users: bool = (
985
+ False # If True, only upgrade users who have pending profiles
986
+ )
987
+
988
+
989
+ class UpgradeProfilesResponse(BaseModel):
990
+ success: bool
991
+ profiles_archived: int = 0
992
+ profiles_promoted: int = 0
993
+ profiles_deleted: int = 0
994
+ message: str = ""
995
+
996
+
997
+ class DowngradeProfilesRequest(BaseModel):
998
+ user_id: str | None = None # None means "all users"
999
+ profile_ids: list[str] | None = None
1000
+ only_affected_users: bool = (
1001
+ False # If True, only downgrade users who have archived profiles
1002
+ )
1003
+
1004
+
1005
+ class DowngradeProfilesResponse(BaseModel):
1006
+ success: bool
1007
+ profiles_demoted: int = 0
1008
+ profiles_restored: int = 0
1009
+ message: str = ""
1010
+
1011
+
1012
+ class UpgradeUserPlaybooksRequest(BaseModel):
1013
+ agent_version: str | None = None
1014
+ playbook_name: str | None = None
1015
+ archive_current: bool = True
1016
+
1017
+
1018
+ class UpgradeUserPlaybooksResponse(BaseModel):
1019
+ success: bool
1020
+ user_playbooks_deleted: int = 0
1021
+ user_playbooks_archived: int = 0
1022
+ user_playbooks_promoted: int = 0
1023
+ message: str = ""
1024
+
1025
+
1026
+ class DowngradeUserPlaybooksRequest(BaseModel):
1027
+ agent_version: str | None = None
1028
+ playbook_name: str | None = None
1029
+
1030
+
1031
+ class DowngradeUserPlaybooksResponse(BaseModel):
1032
+ success: bool
1033
+ user_playbooks_demoted: int = 0
1034
+ user_playbooks_restored: int = 0
1035
+ message: str = ""
1036
+
1037
+
1038
+ # ===============================
1039
+ # Operation Status Models
1040
+ # ===============================
1041
+ class OperationStatusInfo(BaseModel):
1042
+ service_name: str
1043
+ status: OperationStatus
1044
+ started_at: int
1045
+ completed_at: int | None = None
1046
+ total_users: int = 0
1047
+ processed_users: int = 0
1048
+ failed_users: int = 0
1049
+ current_user_id: str | None = None
1050
+ processed_user_ids: list[str] = []
1051
+ failed_user_ids: list[dict] = [] # [{"user_id": "...", "error": "..."}]
1052
+ request_params: dict = {}
1053
+ stats: dict = {}
1054
+ error_message: str | None = None
1055
+ progress_percentage: float = Field(default=0.0, ge=0.0, le=100.0)
1056
+
1057
+
1058
+ class GetOperationStatusRequest(BaseModel):
1059
+ service_name: str = "profile_generation"
1060
+
1061
+
1062
+ class GetOperationStatusResponse(BaseModel):
1063
+ success: bool
1064
+ operation_status: OperationStatusInfo | None = None
1065
+ msg: str | None = None
1066
+
1067
+
1068
+ class CancelOperationRequest(BaseModel):
1069
+ service_name: str | None = None # None cancels both services
1070
+
1071
+
1072
+ class CancelOperationResponse(BaseModel):
1073
+ success: bool
1074
+ cancelled_services: list[str] = []
1075
+ msg: str | None = None
1076
+
1077
+
1078
+ # Admin cache invalidation — explicit eviction of the per-org Reflexio cache.
1079
+ class AdminInvalidateCacheRequest(BaseModel):
1080
+ """Request body for ``POST /api/admin/cache/invalidate``.
1081
+
1082
+ The optional ``org_id`` is a verification token: when supplied it
1083
+ must match the caller's resolved org_id, otherwise the server
1084
+ rejects with 403. This guards against a misconfigured client
1085
+ accidentally invalidating someone else's cache. Cross-org admin
1086
+ invalidation is intentionally out of scope for this endpoint.
1087
+ """
1088
+
1089
+ org_id: str | None = None
1090
+
1091
+
1092
+ class AdminInvalidateCacheResponse(BaseModel):
1093
+ """Result of an admin cache invalidation call.
1094
+
1095
+ Attributes:
1096
+ invalidated (bool): True when an entry was evicted, False when
1097
+ no entry was cached for the org (still a successful no-op).
1098
+ org_id (str): The org_id that was targeted (always the caller's
1099
+ own org).
1100
+ """
1101
+
1102
+ invalidated: bool
1103
+ org_id: str