claude-smart 0.2.46 → 0.2.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/README.md +19 -11
- package/bin/claude-smart.js +290 -68
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.codex-plugin/plugin.json +1 -1
- package/plugin/README.md +11 -10
- package/plugin/dashboard/app/layout.tsx +20 -0
- package/plugin/dashboard/app/sessions/[sessionId]/page.tsx +36 -2
- package/plugin/dashboard/package-lock.json +61 -390
- package/plugin/dashboard/package.json +2 -2
- package/plugin/opencode/dist/server.mjs +76 -2
- package/plugin/opencode/server.mts +79 -2
- package/plugin/pyproject.toml +6 -2
- package/plugin/scripts/smart-install.sh +7 -1
- package/plugin/src/claude_smart/cli.py +210 -22
- package/plugin/src/claude_smart/context_format.py +9 -9
- package/plugin/src/claude_smart/cs_cite.py +66 -19
- package/plugin/uv.lock +5 -5
- package/plugin/vendor/reflexio/.env.example +7 -0
- package/plugin/vendor/reflexio/README.md +3 -3
- package/plugin/vendor/reflexio/pyproject.toml +2 -1
- package/plugin/vendor/reflexio/reflexio/README.md +11 -6
- package/plugin/vendor/reflexio/reflexio/cli/bootstrap_config.py +1 -1
- package/plugin/vendor/reflexio/reflexio/cli/commands/setup_cmd.py +2 -2
- package/plugin/vendor/reflexio/reflexio/cli/utils.py +44 -1
- package/plugin/vendor/reflexio/reflexio/client/client.py +97 -0
- package/plugin/vendor/reflexio/reflexio/lib/_agent_playbook.py +8 -0
- package/plugin/vendor/reflexio/reflexio/lib/_base.py +15 -0
- package/plugin/vendor/reflexio/reflexio/lib/_config.py +23 -18
- package/plugin/vendor/reflexio/reflexio/lib/_generation.py +9 -8
- package/plugin/vendor/reflexio/reflexio/lib/_interactions.py +16 -1
- package/plugin/vendor/reflexio/reflexio/lib/_profiles.py +27 -16
- package/plugin/vendor/reflexio/reflexio/lib/_search.py +27 -5
- package/plugin/vendor/reflexio/reflexio/lib/_user_playbook.py +9 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/domain/__init__.py +1 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/domain/enums.py +1 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/domain/governance.py +117 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/retriever_schema.py +45 -3
- package/plugin/vendor/reflexio/reflexio/models/config_schema.py +37 -0
- package/plugin/vendor/reflexio/reflexio/server/README.md +38 -9
- package/plugin/vendor/reflexio/reflexio/server/__init__.py +21 -2
- package/plugin/vendor/reflexio/reflexio/server/api.py +274 -3267
- package/plugin/vendor/reflexio/reflexio/server/api_endpoints/README.md +4 -3
- package/plugin/vendor/reflexio/reflexio/server/api_endpoints/publisher_api.py +16 -1
- package/plugin/vendor/reflexio/reflexio/server/api_endpoints/request_context.py +1 -1
- package/plugin/vendor/reflexio/reflexio/server/{_auth.py → auth.py} +2 -0
- package/plugin/vendor/reflexio/reflexio/server/cache/reflexio_cache.py +62 -36
- package/plugin/vendor/reflexio/reflexio/server/deployment_profile.py +69 -0
- package/plugin/vendor/reflexio/reflexio/server/extensions.py +213 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/_litellm_embedding.py +424 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/_litellm_json_extraction.py +249 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/_litellm_structured_output.py +195 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/_litellm_subprocess.py +152 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/_litellm_text_generation.py +980 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/_litellm_types.py +110 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/litellm_client.py +73 -1819
- package/plugin/vendor/reflexio/reflexio/server/llm/model_defaults.py +4 -4
- package/plugin/vendor/reflexio/reflexio/server/llm/providers/claude_code_provider.py +57 -5
- package/plugin/vendor/reflexio/reflexio/server/llm/rerank/cross_encoder_reranker.py +12 -1
- package/plugin/vendor/reflexio/reflexio/server/middleware.py +244 -0
- package/plugin/vendor/reflexio/reflexio/server/operation_limiter.py +9 -1
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context/v4.4.0.prompt.md +14 -2
- package/plugin/vendor/reflexio/reflexio/server/rate_limit.py +79 -0
- package/plugin/vendor/reflexio/reflexio/server/routes/__init__.py +6 -0
- package/plugin/vendor/reflexio/reflexio/server/routes/_common.py +25 -0
- package/plugin/vendor/reflexio/reflexio/server/routes/_metering.py +98 -0
- package/plugin/vendor/reflexio/reflexio/server/routes/braintrust.py +129 -0
- package/plugin/vendor/reflexio/reflexio/server/routes/config.py +210 -0
- package/plugin/vendor/reflexio/reflexio/server/routes/evaluation.py +549 -0
- package/plugin/vendor/reflexio/reflexio/server/routes/interactions.py +259 -0
- package/plugin/vendor/reflexio/reflexio/server/routes/playbooks.py +578 -0
- package/plugin/vendor/reflexio/reflexio/server/routes/profiles.py +423 -0
- package/plugin/vendor/reflexio/reflexio/server/routes/provenance.py +345 -0
- package/plugin/vendor/reflexio/reflexio/server/routes/search.py +349 -0
- package/plugin/vendor/reflexio/reflexio/server/routes/system.py +261 -0
- package/plugin/vendor/reflexio/reflexio/server/scheduling.py +132 -0
- package/plugin/vendor/reflexio/reflexio/server/services/README.md +5 -2
- package/plugin/vendor/reflexio/reflexio/server/services/base_generation/__init__.py +38 -0
- package/plugin/vendor/reflexio/reflexio/server/services/base_generation/_batch_progress.py +298 -0
- package/plugin/vendor/reflexio/reflexio/server/services/base_generation/_config_filter.py +152 -0
- package/plugin/vendor/reflexio/reflexio/server/services/base_generation/_extraction_lifecycle.py +243 -0
- package/plugin/vendor/reflexio/reflexio/server/services/base_generation/_should_run.py +299 -0
- package/plugin/vendor/reflexio/reflexio/server/services/base_generation/_status_change.py +273 -0
- package/plugin/vendor/reflexio/reflexio/server/services/base_generation/_usage_billing.py +258 -0
- package/plugin/vendor/reflexio/reflexio/server/services/base_generation_service.py +17 -1183
- package/plugin/vendor/reflexio/reflexio/server/services/deduplication_utils.py +8 -1
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/resume_scheduler.py +26 -41
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/resume_worker.py +8 -0
- package/plugin/vendor/reflexio/reflexio/server/services/generation_service.py +232 -123
- package/plugin/vendor/reflexio/reflexio/server/services/governance/config.py +52 -0
- package/plugin/vendor/reflexio/reflexio/server/services/governance/service.py +378 -0
- package/plugin/vendor/reflexio/reflexio/server/services/governance/subject_refs.py +34 -0
- package/plugin/vendor/reflexio/reflexio/server/services/lineage/gc_scheduler.py +385 -78
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/README.md +9 -1
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/aggregation_prompt_processing.py +100 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/components/aggregator.py +121 -525
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/components/aggregator_clustering.py +184 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/components/aggregator_postprocessing.py +130 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/components/aggregator_prompt_formatting.py +212 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/components/consolidator.py +258 -69
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/service.py +9 -9
- package/plugin/vendor/reflexio/reflexio/server/services/profile/components/extractor.py +3 -2
- package/plugin/vendor/reflexio/reflexio/server/services/publish_learning_worker.py +288 -0
- package/plugin/vendor/reflexio/reflexio/server/services/retrieval/recency.py +211 -0
- package/plugin/vendor/reflexio/reflexio/server/services/retrieval/relevance_floor.py +29 -13
- package/plugin/vendor/reflexio/reflexio/server/services/storage/error.py +4 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/governance_validation.py +681 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/__init__.py +43 -6
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_agent_run.py +10 -1167
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_base.py +58 -351
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_extras.py +49 -19
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_governance.py +452 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_lineage.py +11 -4
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_playbook.py +1 -2133
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_profiles.py +7 -1126
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_requests.py +73 -33
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_share_links.py +30 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/agent_run/__init__.py +9 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/agent_run/_agent_run_store.py +506 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/agent_run/_pending_tool_call_store.py +704 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/agent_run/_run_tool_dependency_store.py +123 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/base/__init__.py +6 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/base/_deletion.py +263 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/base/_fts_vec.py +132 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/governance/__init__.py +13 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/governance/_audit.py +122 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/governance/_erase_execution.py +465 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/governance/_purge.py +387 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/governance/_rebuild_hide.py +332 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/governance/_subject_barrier.py +511 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/playbook/__init__.py +13 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/playbook/_agent.py +955 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/playbook/_eval_results.py +189 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/playbook/_optimization.py +247 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/playbook/_source_linkage.py +145 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/playbook/_user.py +844 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/profiles/__init__.py +9 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/profiles/_interaction_store.py +263 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/profiles/_profile_store.py +896 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/profiles/_search.py +270 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/__init__.py +50 -9
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_agent_run.py +64 -370
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_extras.py +4 -4
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_playbook.py +0 -909
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_requests.py +2 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_share_links.py +20 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/agent_run/__init__.py +9 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/agent_run/_agent_run_store.py +86 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/agent_run/_models.py +195 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/agent_run/_pending_tool_call_store.py +148 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/agent_run/_run_tool_dependency_store.py +38 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/governance/__init__.py +13 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/governance/_audit.py +29 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/governance/_erase_execution.py +30 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/governance/_purge.py +74 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/governance/_rebuild_hide.py +32 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/governance/_subject_barrier.py +49 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/playbook/__init__.py +13 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/playbook/_agent.py +365 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/playbook/_eval_results.py +124 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/playbook/_optimization.py +85 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/playbook/_source_linkage.py +47 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/playbook/_user.py +333 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/profiles/__init__.py +9 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/profiles/_interaction_store.py +73 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/{_profiles.py → profiles/_profile_store.py} +57 -86
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/profiles/_search.py +32 -0
- package/plugin/vendor/reflexio/reflexio/server/services/unified_search_service.py +153 -12
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/user_detail_stripping.py +0 -84
|
@@ -1,378 +1,72 @@
|
|
|
1
|
-
"""Shared storage types and helpers for resumable extraction agent runs.
|
|
1
|
+
"""Shared storage types and helpers for resumable extraction agent runs.
|
|
2
|
+
|
|
3
|
+
Residual holder for the ``_agent_run.py`` decomposition. The 18 shared
|
|
4
|
+
non-class symbols live in the leaf ``agent_run/_models.py`` and are re-exported
|
|
5
|
+
here so ``storage_base/__init__.py`` keeps importing them from ``._agent_run``
|
|
6
|
+
byte-identically. ``AgentRunMixin`` survives as a thin COMPOSITE ABC:
|
|
7
|
+
``AgentRunStoreABC`` supplies the agent-run lifecycle stubs,
|
|
8
|
+
``PendingToolCallStoreABC`` supplies the pending-tool-call stubs,
|
|
9
|
+
``RunToolDependencyStoreABC`` supplies the run-tool-dependency stubs, and only
|
|
10
|
+
the public helper staticmethods stay inline here. All twenty-three agent-run
|
|
11
|
+
methods now live in the three ``agent_run`` sub-mixins.
|
|
12
|
+
"""
|
|
2
13
|
|
|
3
14
|
from __future__ import annotations
|
|
4
15
|
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
from
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
""
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
class AgentRunRecord:
|
|
58
|
-
id: str
|
|
59
|
-
binding: AgentBinding
|
|
60
|
-
status: AgentRunStatus
|
|
61
|
-
generation_request_snapshot: dict[str, Any]
|
|
62
|
-
service_config_snapshot: dict[str, Any] | None = None
|
|
63
|
-
agent_context_snapshot: str | None = None
|
|
64
|
-
committed_output: dict[str, Any] | None = None
|
|
65
|
-
pending_tool_call_ids: list[str] = field(default_factory=list)
|
|
66
|
-
max_steps_remaining: int | None = None
|
|
67
|
-
resume_attempts: int = 0
|
|
68
|
-
finalization_attempts: int = 0
|
|
69
|
-
next_resume_at: datetime | None = None
|
|
70
|
-
claimed_by: str | None = None
|
|
71
|
-
claimed_at: datetime | None = None
|
|
72
|
-
agent_completed_at: datetime | None = None
|
|
73
|
-
finalized_at: datetime | None = None
|
|
74
|
-
created_at: datetime | None = None
|
|
75
|
-
updated_at: datetime | None = None
|
|
76
|
-
expires_at: datetime | None = None
|
|
77
|
-
last_error: str | None = None
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
@dataclass(frozen=True)
|
|
81
|
-
class PendingToolCallRecord:
|
|
82
|
-
id: str
|
|
83
|
-
org_id: str
|
|
84
|
-
scope: dict[str, Any]
|
|
85
|
-
scope_hash: str
|
|
86
|
-
tool_name: str
|
|
87
|
-
dedup_key: str
|
|
88
|
-
status: PendingToolCallStatus
|
|
89
|
-
question_text: str
|
|
90
|
-
args: dict[str, Any] = field(default_factory=dict)
|
|
91
|
-
tags: list[str] = field(default_factory=list)
|
|
92
|
-
user_id: str | None = None
|
|
93
|
-
answer_format: str | None = None
|
|
94
|
-
result: dict[str, Any] | None = None
|
|
95
|
-
embedding: list[float] | None = None
|
|
96
|
-
superseded_by: str | None = None
|
|
97
|
-
created_at: datetime | None = None
|
|
98
|
-
resolved_at: datetime | None = None
|
|
99
|
-
expires_at: datetime | None = None
|
|
100
|
-
cache_until: datetime | None = None
|
|
101
|
-
valid_until: datetime | None = None
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
@dataclass(frozen=True)
|
|
105
|
-
class RunToolDependencyRecord:
|
|
106
|
-
run_id: str
|
|
107
|
-
pending_tool_call_id: str
|
|
108
|
-
dependency_kind: RunToolDependencyKind = RunToolDependencyKind.FOLLOWUP
|
|
109
|
-
resolved_at: datetime | None = None
|
|
110
|
-
consumed_at: datetime | None = None
|
|
111
|
-
created_at: datetime | None = None
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
@dataclass(frozen=True)
|
|
115
|
-
class PendingToolCallUpsertResult:
|
|
116
|
-
pending_tool_call: PendingToolCallRecord
|
|
117
|
-
created: bool
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
@dataclass(frozen=True)
|
|
121
|
-
class PriorAnswerMatch:
|
|
122
|
-
pending_tool_call_id: str
|
|
123
|
-
status: PendingToolCallStatus
|
|
124
|
-
question_text: str
|
|
125
|
-
result: dict[str, Any] | None
|
|
126
|
-
valid_until: datetime | None
|
|
127
|
-
answer_format: str | None = None
|
|
128
|
-
created_at: datetime | None = None
|
|
129
|
-
resolved_at: datetime | None = None
|
|
130
|
-
expires_at: datetime | None = None
|
|
131
|
-
similarity: float | None = None
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
def canonical_json(value: Any) -> str:
|
|
135
|
-
"""Return deterministic compact JSON for storage hashes."""
|
|
136
|
-
return json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
def build_scope_hash(scope: dict[str, Any]) -> str:
|
|
140
|
-
"""Stable hash for a tool scope dictionary."""
|
|
141
|
-
return hashlib.sha256(canonical_json(scope).encode("utf-8")).hexdigest()
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
def human_feedback_scope(org_id: str) -> dict[str, str]:
|
|
145
|
-
"""Human feedback is always org-scoped, never user-scoped."""
|
|
146
|
-
return {"org_id": org_id, "scope_kind": "org"}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
def normalize_dedup_text(value: str | None) -> str:
|
|
150
|
-
"""Normalize text before pending-tool-call dedup hashing."""
|
|
151
|
-
if value is None:
|
|
152
|
-
return ""
|
|
153
|
-
normalized = unicodedata.normalize("NFKC", value)
|
|
154
|
-
normalized = _WHITESPACE_RE.sub(" ", normalized.strip())
|
|
155
|
-
return normalized.casefold()
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
def build_pending_tool_call_dedup_key(
|
|
159
|
-
*,
|
|
160
|
-
tool_name: str,
|
|
161
|
-
question_text: str,
|
|
162
|
-
answer_format: str | None = None,
|
|
163
|
-
) -> str:
|
|
164
|
-
"""Stable dedup hash for a normalized tool question."""
|
|
165
|
-
parts = (
|
|
166
|
-
normalize_dedup_text(tool_name),
|
|
167
|
-
normalize_dedup_text(question_text),
|
|
168
|
-
normalize_dedup_text(answer_format),
|
|
169
|
-
)
|
|
170
|
-
return hashlib.sha256("\n".join(parts).encode("utf-8")).hexdigest()
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
def not_applicable_tool_result() -> dict[str, Any]:
|
|
174
|
-
return {"answer": NOT_APPLICABLE_ANSWER, "not_applicable": True}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
def is_not_applicable_tool_result(result: dict[str, Any] | None) -> bool:
|
|
178
|
-
return isinstance(result, dict) and result.get("not_applicable") is True
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
def embedding_similarity(a: list[float] | None, b: list[float] | None) -> float | None:
|
|
182
|
-
"""Cosine similarity for optional embedding vectors."""
|
|
183
|
-
if not a or not b or len(a) != len(b):
|
|
184
|
-
return None
|
|
185
|
-
dot = sum(x * y for x, y in zip(a, b, strict=True))
|
|
186
|
-
mag_a_sq = sum(x * x for x in a)
|
|
187
|
-
mag_b_sq = sum(y * y for y in b)
|
|
188
|
-
if mag_a_sq == 0.0 or mag_b_sq == 0.0:
|
|
189
|
-
return None
|
|
190
|
-
return dot / ((mag_a_sq**0.5) * (mag_b_sq**0.5))
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
class AgentRunMixin:
|
|
16
|
+
from .agent_run import (
|
|
17
|
+
AgentRunStoreABC,
|
|
18
|
+
PendingToolCallStoreABC,
|
|
19
|
+
RunToolDependencyStoreABC,
|
|
20
|
+
)
|
|
21
|
+
from .agent_run._models import (
|
|
22
|
+
NOT_APPLICABLE_ANSWER,
|
|
23
|
+
AgentBinding,
|
|
24
|
+
AgentRunRecord,
|
|
25
|
+
AgentRunStatus,
|
|
26
|
+
PendingToolCallRecord,
|
|
27
|
+
PendingToolCallStatus,
|
|
28
|
+
PendingToolCallUpsertResult,
|
|
29
|
+
PriorAnswerMatch,
|
|
30
|
+
RunToolDependencyKind,
|
|
31
|
+
RunToolDependencyRecord,
|
|
32
|
+
build_pending_tool_call_dedup_key,
|
|
33
|
+
build_scope_hash,
|
|
34
|
+
canonical_json,
|
|
35
|
+
embedding_similarity,
|
|
36
|
+
human_feedback_scope,
|
|
37
|
+
is_not_applicable_tool_result,
|
|
38
|
+
normalize_dedup_text,
|
|
39
|
+
not_applicable_tool_result,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
__all__ = [
|
|
43
|
+
"NOT_APPLICABLE_ANSWER",
|
|
44
|
+
"AgentBinding",
|
|
45
|
+
"AgentRunMixin",
|
|
46
|
+
"AgentRunRecord",
|
|
47
|
+
"AgentRunStatus",
|
|
48
|
+
"PendingToolCallRecord",
|
|
49
|
+
"PendingToolCallStatus",
|
|
50
|
+
"PendingToolCallUpsertResult",
|
|
51
|
+
"PriorAnswerMatch",
|
|
52
|
+
"RunToolDependencyKind",
|
|
53
|
+
"RunToolDependencyRecord",
|
|
54
|
+
"build_pending_tool_call_dedup_key",
|
|
55
|
+
"build_scope_hash",
|
|
56
|
+
"canonical_json",
|
|
57
|
+
"embedding_similarity",
|
|
58
|
+
"human_feedback_scope",
|
|
59
|
+
"is_not_applicable_tool_result",
|
|
60
|
+
"normalize_dedup_text",
|
|
61
|
+
"not_applicable_tool_result",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class AgentRunMixin(
|
|
66
|
+
AgentRunStoreABC, PendingToolCallStoreABC, RunToolDependencyStoreABC
|
|
67
|
+
):
|
|
194
68
|
"""Backend-neutral helpers shared by resumable extraction storage backends."""
|
|
195
69
|
|
|
196
70
|
build_scope_hash = staticmethod(build_scope_hash)
|
|
197
71
|
human_feedback_scope = staticmethod(human_feedback_scope)
|
|
198
72
|
build_pending_tool_call_dedup_key = staticmethod(build_pending_tool_call_dedup_key)
|
|
199
|
-
|
|
200
|
-
def create_agent_run(self, record: AgentRunRecord) -> AgentRunRecord:
|
|
201
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
202
|
-
|
|
203
|
-
def get_agent_run(self, run_id: str) -> AgentRunRecord | None:
|
|
204
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
205
|
-
|
|
206
|
-
def update_agent_run_status(
|
|
207
|
-
self,
|
|
208
|
-
run_id: str,
|
|
209
|
-
status: AgentRunStatus,
|
|
210
|
-
*,
|
|
211
|
-
committed_output: dict[str, Any] | None = None,
|
|
212
|
-
pending_tool_call_ids: list[str] | None = None,
|
|
213
|
-
max_steps_remaining: int | None = None,
|
|
214
|
-
next_resume_at: datetime | None = None,
|
|
215
|
-
last_error: str | None = None,
|
|
216
|
-
increment_finalization_attempts: bool = False,
|
|
217
|
-
expected_statuses: tuple[AgentRunStatus, ...] | None = None,
|
|
218
|
-
) -> AgentRunRecord | None:
|
|
219
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
220
|
-
|
|
221
|
-
def fail_running_agent_runs_for_request(
|
|
222
|
-
self,
|
|
223
|
-
*,
|
|
224
|
-
org_id: str,
|
|
225
|
-
extractor_kind: str,
|
|
226
|
-
user_id: str | None,
|
|
227
|
-
request_id: str,
|
|
228
|
-
last_error: str,
|
|
229
|
-
) -> int:
|
|
230
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
231
|
-
|
|
232
|
-
def create_pending_tool_call(
|
|
233
|
-
self, record: PendingToolCallRecord
|
|
234
|
-
) -> PendingToolCallRecord:
|
|
235
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
236
|
-
|
|
237
|
-
def create_or_attach_pending_tool_call(
|
|
238
|
-
self,
|
|
239
|
-
*,
|
|
240
|
-
record: PendingToolCallRecord,
|
|
241
|
-
dependency: RunToolDependencyRecord,
|
|
242
|
-
now: datetime | None = None,
|
|
243
|
-
) -> PendingToolCallUpsertResult:
|
|
244
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
245
|
-
|
|
246
|
-
def get_pending_tool_call(self, call_id: str) -> PendingToolCallRecord | None:
|
|
247
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
248
|
-
|
|
249
|
-
def list_pending_tool_calls(
|
|
250
|
-
self,
|
|
251
|
-
*,
|
|
252
|
-
status: PendingToolCallStatus | None = None,
|
|
253
|
-
limit: int = 100,
|
|
254
|
-
) -> list[PendingToolCallRecord]:
|
|
255
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
256
|
-
|
|
257
|
-
def cancel_pending_tool_call(
|
|
258
|
-
self,
|
|
259
|
-
call_id: str,
|
|
260
|
-
*,
|
|
261
|
-
cancelled_at: datetime | None = None,
|
|
262
|
-
) -> PendingToolCallRecord | None:
|
|
263
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
264
|
-
|
|
265
|
-
def expire_pending_tool_calls(
|
|
266
|
-
self,
|
|
267
|
-
*,
|
|
268
|
-
now: datetime | None = None,
|
|
269
|
-
limit: int = 100,
|
|
270
|
-
) -> int:
|
|
271
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
272
|
-
|
|
273
|
-
def find_active_pending_tool_call(
|
|
274
|
-
self,
|
|
275
|
-
*,
|
|
276
|
-
org_id: str,
|
|
277
|
-
scope_hash: str,
|
|
278
|
-
tool_name: str,
|
|
279
|
-
dedup_key: str,
|
|
280
|
-
now: datetime | None = None,
|
|
281
|
-
) -> PendingToolCallRecord | None:
|
|
282
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
283
|
-
|
|
284
|
-
def search_prior_tool_calls(
|
|
285
|
-
self,
|
|
286
|
-
*,
|
|
287
|
-
org_id: str,
|
|
288
|
-
scope_hash: str,
|
|
289
|
-
tool_name: str,
|
|
290
|
-
query_embedding: list[float] | None = None,
|
|
291
|
-
now: datetime | None = None,
|
|
292
|
-
limit: int = 8,
|
|
293
|
-
) -> list[PriorAnswerMatch]:
|
|
294
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
295
|
-
|
|
296
|
-
def attach_run_tool_dependency(
|
|
297
|
-
self, record: RunToolDependencyRecord
|
|
298
|
-
) -> RunToolDependencyRecord:
|
|
299
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
300
|
-
|
|
301
|
-
def count_unresolved_followup_dependencies(
|
|
302
|
-
self,
|
|
303
|
-
*,
|
|
304
|
-
org_id: str,
|
|
305
|
-
extractor_kind: str,
|
|
306
|
-
tool_name: str,
|
|
307
|
-
) -> int:
|
|
308
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
309
|
-
|
|
310
|
-
def list_run_tool_dependencies(self, run_id: str) -> list[RunToolDependencyRecord]:
|
|
311
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
312
|
-
|
|
313
|
-
def resolve_pending_tool_call(
|
|
314
|
-
self,
|
|
315
|
-
call_id: str,
|
|
316
|
-
*,
|
|
317
|
-
result: dict[str, Any],
|
|
318
|
-
resolved_at: datetime | None = None,
|
|
319
|
-
valid_for_seconds: int,
|
|
320
|
-
) -> PendingToolCallRecord | None:
|
|
321
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
322
|
-
|
|
323
|
-
def update_resolved_pending_tool_call_result(
|
|
324
|
-
self,
|
|
325
|
-
call_id: str,
|
|
326
|
-
*,
|
|
327
|
-
result: dict[str, Any],
|
|
328
|
-
resolved_at: datetime | None = None,
|
|
329
|
-
valid_for_seconds: int,
|
|
330
|
-
) -> PendingToolCallRecord | None:
|
|
331
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
332
|
-
|
|
333
|
-
def mark_pending_tool_call_not_applicable(
|
|
334
|
-
self,
|
|
335
|
-
call_id: str,
|
|
336
|
-
*,
|
|
337
|
-
resolved_at: datetime | None = None,
|
|
338
|
-
valid_for_seconds: int,
|
|
339
|
-
) -> PendingToolCallRecord | None:
|
|
340
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
341
|
-
|
|
342
|
-
def claim_ready_agent_run(
|
|
343
|
-
self,
|
|
344
|
-
*,
|
|
345
|
-
org_id: str,
|
|
346
|
-
worker_id: str,
|
|
347
|
-
now: datetime | None = None,
|
|
348
|
-
claim_ttl_seconds: int = 600,
|
|
349
|
-
) -> AgentRunRecord | None:
|
|
350
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
351
|
-
|
|
352
|
-
def claim_finalization_failed_agent_run(
|
|
353
|
-
self,
|
|
354
|
-
*,
|
|
355
|
-
org_id: str,
|
|
356
|
-
worker_id: str,
|
|
357
|
-
now: datetime | None = None,
|
|
358
|
-
claim_ttl_seconds: int = 600,
|
|
359
|
-
) -> AgentRunRecord | None:
|
|
360
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
361
|
-
|
|
362
|
-
def list_resumable_work_org_ids(
|
|
363
|
-
self,
|
|
364
|
-
*,
|
|
365
|
-
now: datetime | None = None,
|
|
366
|
-
limit: int = 1000,
|
|
367
|
-
) -> list[str]:
|
|
368
|
-
"""Return distinct org_ids that have actionable resumable-extraction work.
|
|
369
|
-
|
|
370
|
-
Cross-org maintenance query (intentionally NOT scoped to ``self.org_id``):
|
|
371
|
-
the resume scheduler uses it to discover every org that has a run ready
|
|
372
|
-
to resume, a run awaiting finalization retry, or a pending tool call that
|
|
373
|
-
can be expired, so per-org workers can be driven for all of them.
|
|
374
|
-
"""
|
|
375
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
376
|
-
|
|
377
|
-
def consume_run_tool_dependencies(self, run_id: str) -> int:
|
|
378
|
-
raise NotImplementedError(f"{type(self).__name__} does not support agent runs")
|
|
@@ -29,10 +29,10 @@ class ExtrasMixin:
|
|
|
29
29
|
dict: Dictionary containing:
|
|
30
30
|
- current_period: Stats for the current period (days_back)
|
|
31
31
|
- previous_period: Stats for the previous period (for trend calculation)
|
|
32
|
-
- interactions_time_series:
|
|
33
|
-
- profiles_time_series:
|
|
34
|
-
- playbooks_time_series:
|
|
35
|
-
- evaluations_time_series:
|
|
32
|
+
- interactions_time_series: Daily bucketed interaction counts
|
|
33
|
+
- profiles_time_series: Daily bucketed profile counts
|
|
34
|
+
- playbooks_time_series: Daily bucketed playbook counts
|
|
35
|
+
- evaluations_time_series: Daily bucketed success rates with optional counts
|
|
36
36
|
"""
|
|
37
37
|
raise NotImplementedError
|
|
38
38
|
|