execweave 1.0.0__py3-none-any.whl
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.
- execweave/__init__.py +3 -0
- execweave/__main__.py +5 -0
- execweave/_conversation_records_core.py +902 -0
- execweave/_dashboard_shell_base.py +148 -0
- execweave/_http_proxy_base.py +565 -0
- execweave/_http_proxy_bounded.py +560 -0
- execweave/_http_proxy_stage.py +509 -0
- execweave/acceptance_output.py +19 -0
- execweave/agent_bootstrap.py +395 -0
- execweave/agent_topology.py +313 -0
- execweave/agent_trace.py +1162 -0
- execweave/agy_preview_sanitize.py +102 -0
- execweave/analysis.py +427 -0
- execweave/anthropic.py +228 -0
- execweave/anthropic_cli.py +171 -0
- execweave/anthropic_full_fidelity.py +385 -0
- execweave/antigravity_adapter.py +112 -0
- execweave/antigravity_adapter_base.py +479 -0
- execweave/antigravity_full_fidelity.py +656 -0
- execweave/antigravity_full_fidelity_base.py +172 -0
- execweave/antigravity_full_fidelity_collaboration_base.py +451 -0
- execweave/antigravity_hook_cli.py +209 -0
- execweave/antigravity_record.py +96 -0
- execweave/antigravity_subagent_linkage.py +449 -0
- execweave/antigravity_trace_capability.py +39 -0
- execweave/auto_specialized.py +547 -0
- execweave/backends.py +102 -0
- execweave/benchmark.py +80 -0
- execweave/claude_adapter.py +517 -0
- execweave/claude_child_transcript.py +314 -0
- execweave/claude_delegation.py +136 -0
- execweave/claude_full_fidelity.py +396 -0
- execweave/claude_hook_cli.py +209 -0
- execweave/claude_hook_contract.py +943 -0
- execweave/claude_model_observer.py +353 -0
- execweave/claude_record.py +106 -0
- execweave/cli.py +629 -0
- execweave/codex_adapter.py +455 -0
- execweave/codex_conversation.py +621 -0
- execweave/codex_full_fidelity.py +287 -0
- execweave/codex_hook_cli.py +301 -0
- execweave/codex_hook_entry.py +207 -0
- execweave/codex_hook_lifecycle.py +363 -0
- execweave/codex_message_diagnostics.py +322 -0
- execweave/codex_message_transport_diagnostics.py +399 -0
- execweave/codex_record.py +199 -0
- execweave/codex_rollout_structures.py +402 -0
- execweave/codex_rollout_trace.py +56 -0
- execweave/codex_rollout_trace_base.py +1509 -0
- execweave/collector.py +768 -0
- execweave/command.py +157 -0
- execweave/command_privacy.py +20 -0
- execweave/content_evidence.py +101 -0
- execweave/content_integrity.py +289 -0
- execweave/content_store.py +273 -0
- execweave/controlled_checks.py +561 -0
- execweave/conversation_archive.py +338 -0
- execweave/conversation_message_identity.py +264 -0
- execweave/conversation_preview.py +66 -0
- execweave/conversation_preview_antigravity.py +32 -0
- execweave/conversation_preview_claude.py +31 -0
- execweave/conversation_preview_codex.py +107 -0
- execweave/conversation_preview_common.py +180 -0
- execweave/conversation_preview_generic.py +188 -0
- execweave/conversation_preview_lines.py +133 -0
- execweave/conversation_preview_transcript.py +121 -0
- execweave/conversation_records.py +349 -0
- execweave/conversation_records_antigravity.py +370 -0
- execweave/conversation_records_codex.py +83 -0
- execweave/conversation_records_common.py +17 -0
- execweave/conversation_records_ollama.py +39 -0
- execweave/correlation.py +818 -0
- execweave/cursor_adapter.py +349 -0
- execweave/cursor_delegation.py +87 -0
- execweave/cursor_delegation_base.py +220 -0
- execweave/cursor_full_fidelity.py +489 -0
- execweave/cursor_hook_cli.py +195 -0
- execweave/cursor_hook_contract.py +439 -0
- execweave/cursor_lifecycle.py +159 -0
- execweave/cursor_record.py +96 -0
- execweave/dashboard_shell.py +283 -0
- execweave/delivery_status.py +94 -0
- execweave/entry.py +98 -0
- execweave/evidence_availability.py +113 -0
- execweave/evidence_grade.py +166 -0
- execweave/fidelity.py +304 -0
- execweave/filesystem.py +327 -0
- execweave/finalization.py +92 -0
- execweave/focus.py +118 -0
- execweave/framework_adapters/__init__.py +34 -0
- execweave/framework_adapters/autogen.py +398 -0
- execweave/framework_adapters/base.py +580 -0
- execweave/framework_adapters/camel.py +270 -0
- execweave/framework_adapters/camel_channel.py +71 -0
- execweave/framework_adapters/metagpt.py +315 -0
- execweave/framework_adapters/metagpt_ollama_compat.py +54 -0
- execweave/framework_adapters/metagpt_recording.py +342 -0
- execweave/framework_adapters/registry.py +90 -0
- execweave/graph.py +590 -0
- execweave/graph_ops.py +472 -0
- execweave/hook_command.py +32 -0
- execweave/hook_delivery.py +32 -0
- execweave/hook_input.py +16 -0
- execweave/http_proxy.py +187 -0
- execweave/http_proxy_cli.py +84 -0
- execweave/inference_gateway.py +476 -0
- execweave/inference_gateway_cli.py +211 -0
- execweave/inference_gateway_full_fidelity.py +613 -0
- execweave/inference_identity.py +76 -0
- execweave/inference_identity_cli.py +60 -0
- execweave/integrity.py +235 -0
- execweave/integrity_cli.py +55 -0
- execweave/investigation_index.py +445 -0
- execweave/litellm_callback.py +211 -0
- execweave/litellm_callback_cli.py +42 -0
- execweave/live.py +445 -0
- execweave/live_core.py +972 -0
- execweave/live_view.py +109 -0
- execweave/live_view_extra_style.py +11 -0
- execweave/live_view_markup.py +29 -0
- execweave/live_view_process_layout.py +650 -0
- execweave/live_view_readability.py +502 -0
- execweave/live_view_script_a.py +59 -0
- execweave/live_view_script_b.py +97 -0
- execweave/live_view_script_c.py +59 -0
- execweave/live_view_script_d.py +40 -0
- execweave/live_view_style.py +34 -0
- execweave/model_runtime.py +560 -0
- execweave/model_runtime_cli.py +265 -0
- execweave/model_runtime_full_fidelity.py +519 -0
- execweave/observation.py +53 -0
- execweave/observation_demo.py +69 -0
- execweave/openai_agents.py +267 -0
- execweave/openai_agents_sdk.py +453 -0
- execweave/openai_compatible.py +239 -0
- execweave/openai_compatible_cli.py +189 -0
- execweave/openai_compatible_full_fidelity.py +438 -0
- execweave/opencode_adapter.py +325 -0
- execweave/opencode_event_contract.py +734 -0
- execweave/opencode_full_fidelity.py +198 -0
- execweave/opencode_hook_cli.py +119 -0
- execweave/opencode_plugin_cli.py +150 -0
- execweave/opencode_record.py +96 -0
- execweave/opencode_task_linkage.py +225 -0
- execweave/overhead_benchmark.py +440 -0
- execweave/privacy.py +84 -0
- execweave/private_io.py +465 -0
- execweave/provider_capability.py +578 -0
- execweave/provider_lifecycle.py +282 -0
- execweave/provider_record.py +290 -0
- execweave/reader_identity.py +13 -0
- execweave/redacted_archive.py +906 -0
- execweave/risk.py +106 -0
- execweave/rule_pack.py +359 -0
- execweave/rule_pack_cli.py +57 -0
- execweave/run_assessment.py +200 -0
- execweave/runtime_endpoint_availability.py +44 -0
- execweave/scalability_benchmark.py +195 -0
- execweave/schema.py +62 -0
- execweave/scope.py +85 -0
- execweave/semantic.py +453 -0
- execweave/session_summary.py +159 -0
- execweave/sink.py +71 -0
- execweave/strace_backend.py +927 -0
- execweave/stream_assembly.py +363 -0
- execweave/task_artifacts.py +192 -0
- execweave/task_validation.py +317 -0
- execweave/theme.py +40 -0
- execweave/top.py +599 -0
- execweave/top_cli.py +150 -0
- execweave/validate.py +196 -0
- execweave/vendor/dagre.min.js +815 -0
- execweave/view_cli.py +49 -0
- execweave/viewer.py +474 -0
- execweave/viewer_agent_panel.py +630 -0
- execweave/viewer_agent_panel_antigravity.py +31 -0
- execweave/viewer_agent_panel_claude.py +9 -0
- execweave/viewer_agent_panel_codex.py +50 -0
- execweave/viewer_agent_panel_cursor.py +9 -0
- execweave/viewer_agent_panel_default.py +79 -0
- execweave/viewer_agent_panel_ollama.py +20 -0
- execweave/viewer_agent_panel_opencode.py +9 -0
- execweave/viewer_agent_panel_registry.py +20 -0
- execweave/viewer_archive_verifier.py +178 -0
- execweave/viewer_background_files.py +86 -0
- execweave/viewer_content_browser.py +307 -0
- execweave/viewer_content_health.py +208 -0
- execweave/viewer_content_inspector.py +309 -0
- execweave/viewer_controlled_checks.py +258 -0
- execweave/viewer_conversation_sync.py +115 -0
- execweave/viewer_dashboard_clean.py +405 -0
- execweave/viewer_dashboard_focus.py +127 -0
- execweave/viewer_dashboard_hardening.py +264 -0
- execweave/viewer_dashboard_hardening_v2.py +62 -0
- execweave/viewer_dashboard_projection.py +261 -0
- execweave/viewer_delivery_status.py +155 -0
- execweave/viewer_edge_decross.py +117 -0
- execweave/viewer_execution_flow.py +611 -0
- execweave/viewer_execution_flow_provider_normalization.py +107 -0
- execweave/viewer_execution_flow_safety.py +349 -0
- execweave/viewer_external_endpoints.py +307 -0
- execweave/viewer_flow_canvas.py +1140 -0
- execweave/viewer_flow_layout.py +922 -0
- execweave/viewer_fold_state.py +31 -0
- execweave/viewer_framework_flow.py +68 -0
- execweave/viewer_framework_model_output.py +133 -0
- execweave/viewer_gif.py +278 -0
- execweave/viewer_history_browser.py +225 -0
- execweave/viewer_investigation.py +268 -0
- execweave/viewer_layout_geometry.py +192 -0
- execweave/viewer_layout_v2.py +429 -0
- execweave/viewer_layout_v2_detached.py +25 -0
- execweave/viewer_limits.py +93 -0
- execweave/viewer_live_layout.py +61 -0
- execweave/viewer_message_handoffs.py +114 -0
- execweave/viewer_projection.py +488 -0
- execweave/viewer_projection_base.py +522 -0
- execweave/viewer_projection_bridges.py +214 -0
- execweave/viewer_recorded_sources.py +146 -0
- execweave/viewer_run_assessment.py +274 -0
- execweave/viewer_run_guide.py +175 -0
- execweave/viewer_runtime_evidence.py +258 -0
- execweave/viewer_semantic_projection.py +641 -0
- execweave/viewer_session_flow.py +491 -0
- execweave/viewer_structure_share.py +132 -0
- execweave/viewer_task_validation.py +241 -0
- execweave/viewer_tool_mirror_identity.py +75 -0
- execweave/viewer_workflow_mode.py +127 -0
- execweave/workflow.py +183 -0
- execweave-1.0.0.dist-info/METADATA +462 -0
- execweave-1.0.0.dist-info/RECORD +234 -0
- execweave-1.0.0.dist-info/WHEEL +4 -0
- execweave-1.0.0.dist-info/entry_points.txt +30 -0
- execweave-1.0.0.dist-info/licenses/LICENSE +16 -0
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
from dataclasses import replace
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from .content_evidence import content_observation_event, filter_transport_credentials
|
|
10
|
+
from .content_store import ContentReference, FullFidelityContentStore
|
|
11
|
+
from .inference_gateway import sanitize_gateway_endpoint
|
|
12
|
+
|
|
13
|
+
_CONTENT_FIELDS = frozenset({"messages", "response", "model_parameters", "prompt", "input"})
|
|
14
|
+
_DROP_METADATA_CONTAINERS = frozenset(
|
|
15
|
+
{"headers", "request_headers", "requester_custom_headers", "proxy_headers"}
|
|
16
|
+
)
|
|
17
|
+
_SECRET_FRAGMENTS = (
|
|
18
|
+
"api_key",
|
|
19
|
+
"apikey",
|
|
20
|
+
"authorization",
|
|
21
|
+
"credential",
|
|
22
|
+
"client_secret",
|
|
23
|
+
"access_token",
|
|
24
|
+
"refresh_token",
|
|
25
|
+
"password",
|
|
26
|
+
)
|
|
27
|
+
_URL_KEYS = frozenset(
|
|
28
|
+
{"api_base", "api_base_url", "base_url", "endpoint", "provider_endpoint", "url"}
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _now() -> str:
|
|
33
|
+
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _request_id(payload: dict[str, Any], explicit: str | None) -> str:
|
|
37
|
+
if isinstance(explicit, str) and explicit:
|
|
38
|
+
return explicit
|
|
39
|
+
native = payload.get("id")
|
|
40
|
+
if isinstance(native, str) and native:
|
|
41
|
+
return native
|
|
42
|
+
seed = {key: payload.get(key) for key in ("model", "created", "usage")}
|
|
43
|
+
raw = json.dumps(seed, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
|
|
44
|
+
return hashlib.sha256(raw.encode("utf-8", errors="replace")).hexdigest()[:32]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _request_entity(
|
|
48
|
+
gateway: str,
|
|
49
|
+
response: dict[str, Any],
|
|
50
|
+
*,
|
|
51
|
+
endpoint: str,
|
|
52
|
+
request_id: str | None,
|
|
53
|
+
) -> dict[str, Any]:
|
|
54
|
+
native_id = _request_id(response, request_id)
|
|
55
|
+
return {
|
|
56
|
+
"type": "inference_request",
|
|
57
|
+
"id": f"inference-request:{gateway}:{native_id}",
|
|
58
|
+
"name": native_id,
|
|
59
|
+
"attributes": {"gateway": gateway, "endpoint": sanitize_gateway_endpoint(endpoint)},
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _store(
|
|
64
|
+
store: FullFidelityContentStore,
|
|
65
|
+
value: Any,
|
|
66
|
+
*,
|
|
67
|
+
content_kind: str,
|
|
68
|
+
) -> ContentReference:
|
|
69
|
+
if isinstance(value, str):
|
|
70
|
+
return store.put_text(value, content_kind=content_kind)
|
|
71
|
+
return store.put_json(value, content_kind=content_kind)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _content_event(
|
|
75
|
+
*,
|
|
76
|
+
store: FullFidelityContentStore,
|
|
77
|
+
value: Any,
|
|
78
|
+
content_kind: str,
|
|
79
|
+
timestamp: str,
|
|
80
|
+
provider: str,
|
|
81
|
+
source: dict[str, Any],
|
|
82
|
+
relation: str,
|
|
83
|
+
observed_field: str,
|
|
84
|
+
evidence_source: str,
|
|
85
|
+
attribution: str,
|
|
86
|
+
attributes: dict[str, Any],
|
|
87
|
+
) -> dict[str, Any]:
|
|
88
|
+
return content_observation_event(
|
|
89
|
+
timestamp=timestamp,
|
|
90
|
+
provider=provider,
|
|
91
|
+
source=source,
|
|
92
|
+
reference=_store(store, value, content_kind=content_kind),
|
|
93
|
+
relation=relation,
|
|
94
|
+
observed_field=observed_field,
|
|
95
|
+
evidence_source=evidence_source,
|
|
96
|
+
attribution=attribution,
|
|
97
|
+
event_type=f"inference_gateway.{provider}.content.observed",
|
|
98
|
+
attributes=attributes,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _tool_result_messages(messages: object) -> list[Any]:
|
|
103
|
+
if not isinstance(messages, list):
|
|
104
|
+
return []
|
|
105
|
+
return [
|
|
106
|
+
message
|
|
107
|
+
for message in messages
|
|
108
|
+
if isinstance(message, dict) and message.get("role") in {"tool", "function"}
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _response_tool_calls(response: object) -> list[Any]:
|
|
113
|
+
if not isinstance(response, dict):
|
|
114
|
+
return []
|
|
115
|
+
calls: list[Any] = []
|
|
116
|
+
choices = response.get("choices")
|
|
117
|
+
if isinstance(choices, list):
|
|
118
|
+
for choice in choices:
|
|
119
|
+
if not isinstance(choice, dict) or not isinstance(choice.get("message"), dict):
|
|
120
|
+
continue
|
|
121
|
+
nested = choice["message"].get("tool_calls")
|
|
122
|
+
if isinstance(nested, list):
|
|
123
|
+
calls.extend(nested)
|
|
124
|
+
output = response.get("output")
|
|
125
|
+
if isinstance(output, list):
|
|
126
|
+
for item in output:
|
|
127
|
+
if not isinstance(item, dict):
|
|
128
|
+
continue
|
|
129
|
+
if item.get("type") in {"function_call", "tool_call", "tool_use"}:
|
|
130
|
+
calls.append(item)
|
|
131
|
+
nested = item.get("tool_calls")
|
|
132
|
+
if isinstance(nested, list):
|
|
133
|
+
calls.extend(nested)
|
|
134
|
+
return calls
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _secret_metadata_key(key: str) -> bool:
|
|
138
|
+
lowered = key.lower()
|
|
139
|
+
return (
|
|
140
|
+
lowered in _DROP_METADATA_CONTAINERS
|
|
141
|
+
or lowered == "user_api_key_hash"
|
|
142
|
+
or any(fragment in lowered for fragment in _SECRET_FRAGMENTS)
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _sanitize_metadata(value: Any, *, path: str = "") -> tuple[Any, list[str]]:
|
|
147
|
+
removed: list[str] = []
|
|
148
|
+
if isinstance(value, dict):
|
|
149
|
+
result: dict[str, Any] = {}
|
|
150
|
+
for raw_key, child in value.items():
|
|
151
|
+
key = str(raw_key)
|
|
152
|
+
child_path = f"{path}.{key}" if path else key
|
|
153
|
+
if _secret_metadata_key(key):
|
|
154
|
+
removed.append(child_path)
|
|
155
|
+
continue
|
|
156
|
+
if key.lower() in _URL_KEYS and isinstance(child, str):
|
|
157
|
+
try:
|
|
158
|
+
result[key] = sanitize_gateway_endpoint(child)
|
|
159
|
+
except ValueError:
|
|
160
|
+
removed.append(child_path)
|
|
161
|
+
continue
|
|
162
|
+
result[key], nested = _sanitize_metadata(child, path=child_path)
|
|
163
|
+
removed.extend(nested)
|
|
164
|
+
filtered, transport_removed = filter_transport_credentials(result)
|
|
165
|
+
removed.extend(f"{path}.{item}" if path else item for item in transport_removed)
|
|
166
|
+
return filtered, sorted(set(removed))
|
|
167
|
+
if isinstance(value, list):
|
|
168
|
+
result_list: list[Any] = []
|
|
169
|
+
for index, child in enumerate(value):
|
|
170
|
+
sanitized, nested = _sanitize_metadata(child, path=f"{path}[{index}]")
|
|
171
|
+
result_list.append(sanitized)
|
|
172
|
+
removed.extend(nested)
|
|
173
|
+
return result_list, sorted(set(removed))
|
|
174
|
+
return value, removed
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _metadata_event(
|
|
178
|
+
*,
|
|
179
|
+
metadata: dict[str, Any],
|
|
180
|
+
store: FullFidelityContentStore,
|
|
181
|
+
timestamp: str,
|
|
182
|
+
provider: str,
|
|
183
|
+
source: dict[str, Any],
|
|
184
|
+
evidence_source: str,
|
|
185
|
+
attribution: str,
|
|
186
|
+
content_kind: str,
|
|
187
|
+
observed_field: str,
|
|
188
|
+
attributes: dict[str, Any],
|
|
189
|
+
) -> dict[str, Any] | None:
|
|
190
|
+
sanitized, removed = _sanitize_metadata(metadata)
|
|
191
|
+
if not isinstance(sanitized, dict) or not sanitized:
|
|
192
|
+
return None
|
|
193
|
+
reference = store.put_json(sanitized, content_kind=content_kind)
|
|
194
|
+
if removed:
|
|
195
|
+
reference = replace(reference, complete_from_source=False)
|
|
196
|
+
return content_observation_event(
|
|
197
|
+
timestamp=timestamp,
|
|
198
|
+
provider=provider,
|
|
199
|
+
source=source,
|
|
200
|
+
reference=reference,
|
|
201
|
+
relation="OBSERVED_PROVIDER_METADATA",
|
|
202
|
+
observed_field=observed_field,
|
|
203
|
+
evidence_source=evidence_source,
|
|
204
|
+
attribution=attribution,
|
|
205
|
+
event_type=f"inference_gateway.{provider}.metadata.observed",
|
|
206
|
+
attributes={
|
|
207
|
+
**attributes,
|
|
208
|
+
"transport_credentials_excluded": removed,
|
|
209
|
+
"metadata_complete_from_source": not removed,
|
|
210
|
+
},
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def gateway_response_to_content_events(
|
|
215
|
+
payload: dict[str, Any],
|
|
216
|
+
*,
|
|
217
|
+
store: FullFidelityContentStore,
|
|
218
|
+
gateway_name: str,
|
|
219
|
+
endpoint: str,
|
|
220
|
+
request_id: str | None = None,
|
|
221
|
+
timestamp: str | None = None,
|
|
222
|
+
provider_name: str | None = None,
|
|
223
|
+
deployment_id: str | None = None,
|
|
224
|
+
) -> list[dict[str, Any]]:
|
|
225
|
+
"""Store the complete response supplied to ExecWeave, without claiming request visibility."""
|
|
226
|
+
observed_at = timestamp or _now()
|
|
227
|
+
safe_endpoint = sanitize_gateway_endpoint(endpoint)
|
|
228
|
+
request = _request_entity(gateway_name, payload, endpoint=safe_endpoint, request_id=request_id)
|
|
229
|
+
attrs = {
|
|
230
|
+
"observation_scope": "response_only",
|
|
231
|
+
"request_observed": False,
|
|
232
|
+
"caller_supplied_exchange": False,
|
|
233
|
+
}
|
|
234
|
+
events = [
|
|
235
|
+
_content_event(
|
|
236
|
+
store=store,
|
|
237
|
+
value=payload,
|
|
238
|
+
content_kind=f"inference_gateway.{gateway_name}.response",
|
|
239
|
+
timestamp=observed_at,
|
|
240
|
+
provider=gateway_name,
|
|
241
|
+
source=request,
|
|
242
|
+
relation="OBSERVED_INFERENCE_RESPONSE",
|
|
243
|
+
observed_field="response",
|
|
244
|
+
evidence_source="gateway_response",
|
|
245
|
+
attribution="gateway_api_response",
|
|
246
|
+
attributes=attrs,
|
|
247
|
+
)
|
|
248
|
+
]
|
|
249
|
+
tool_calls = _response_tool_calls(payload)
|
|
250
|
+
if tool_calls:
|
|
251
|
+
events.append(
|
|
252
|
+
_content_event(
|
|
253
|
+
store=store,
|
|
254
|
+
value=tool_calls,
|
|
255
|
+
content_kind=f"inference_gateway.{gateway_name}.assistant_tool_calls",
|
|
256
|
+
timestamp=observed_at,
|
|
257
|
+
provider=gateway_name,
|
|
258
|
+
source=request,
|
|
259
|
+
relation="OBSERVED_ASSISTANT_TOOL_CALLS",
|
|
260
|
+
observed_field="response.tool_calls",
|
|
261
|
+
evidence_source="gateway_response",
|
|
262
|
+
attribution="gateway_api_response",
|
|
263
|
+
attributes=attrs,
|
|
264
|
+
)
|
|
265
|
+
)
|
|
266
|
+
metadata: dict[str, Any] = {
|
|
267
|
+
"gateway": gateway_name,
|
|
268
|
+
"endpoint": safe_endpoint,
|
|
269
|
+
"request_id": request["name"],
|
|
270
|
+
}
|
|
271
|
+
if provider_name:
|
|
272
|
+
metadata["provider_name"] = provider_name
|
|
273
|
+
if deployment_id:
|
|
274
|
+
metadata["deployment_id"] = deployment_id
|
|
275
|
+
metadata_event = _metadata_event(
|
|
276
|
+
metadata=metadata,
|
|
277
|
+
store=store,
|
|
278
|
+
timestamp=observed_at,
|
|
279
|
+
provider=gateway_name,
|
|
280
|
+
source=request,
|
|
281
|
+
evidence_source="gateway_response",
|
|
282
|
+
attribution="gateway_api_response",
|
|
283
|
+
content_kind=f"inference_gateway.{gateway_name}.provider_metadata",
|
|
284
|
+
observed_field="integration_metadata",
|
|
285
|
+
attributes=attrs,
|
|
286
|
+
)
|
|
287
|
+
if metadata_event is not None:
|
|
288
|
+
events.append(metadata_event)
|
|
289
|
+
return events
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def openrouter_response_to_content_events(
|
|
293
|
+
payload: dict[str, Any],
|
|
294
|
+
*,
|
|
295
|
+
store: FullFidelityContentStore,
|
|
296
|
+
endpoint: str = "https://openrouter.ai/api/v1",
|
|
297
|
+
request_id: str | None = None,
|
|
298
|
+
timestamp: str | None = None,
|
|
299
|
+
provider_name: str | None = None,
|
|
300
|
+
deployment_id: str | None = None,
|
|
301
|
+
) -> list[dict[str, Any]]:
|
|
302
|
+
return gateway_response_to_content_events(
|
|
303
|
+
payload,
|
|
304
|
+
store=store,
|
|
305
|
+
gateway_name="openrouter",
|
|
306
|
+
endpoint=endpoint,
|
|
307
|
+
request_id=request_id,
|
|
308
|
+
timestamp=timestamp,
|
|
309
|
+
provider_name=provider_name,
|
|
310
|
+
deployment_id=deployment_id,
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def openrouter_exchange_to_content_events(
|
|
315
|
+
exchange: dict[str, Any],
|
|
316
|
+
*,
|
|
317
|
+
store: FullFidelityContentStore,
|
|
318
|
+
endpoint: str = "https://openrouter.ai/api/v1",
|
|
319
|
+
request_id: str | None = None,
|
|
320
|
+
timestamp: str | None = None,
|
|
321
|
+
provider_name: str | None = None,
|
|
322
|
+
deployment_id: str | None = None,
|
|
323
|
+
) -> list[dict[str, Any]]:
|
|
324
|
+
"""Store caller-supplied request+response evidence; this is not wire interception."""
|
|
325
|
+
request_payload = exchange.get("request")
|
|
326
|
+
response_payload = exchange.get("response")
|
|
327
|
+
if not isinstance(request_payload, dict) or not isinstance(response_payload, dict):
|
|
328
|
+
raise ValueError("OpenRouter exchange requires JSON-object request and response fields")
|
|
329
|
+
observed_at = timestamp or _now()
|
|
330
|
+
safe_endpoint = sanitize_gateway_endpoint(endpoint)
|
|
331
|
+
request = _request_entity(
|
|
332
|
+
"openrouter", response_payload, endpoint=safe_endpoint, request_id=request_id
|
|
333
|
+
)
|
|
334
|
+
attrs = {
|
|
335
|
+
"observation_scope": "caller_supplied_exchange",
|
|
336
|
+
"request_observed": True,
|
|
337
|
+
"caller_supplied_exchange": True,
|
|
338
|
+
"wire_interception_asserted": False,
|
|
339
|
+
}
|
|
340
|
+
common = {
|
|
341
|
+
"store": store,
|
|
342
|
+
"timestamp": observed_at,
|
|
343
|
+
"provider": "openrouter",
|
|
344
|
+
"source": request,
|
|
345
|
+
"evidence_source": "caller_supplied_exchange",
|
|
346
|
+
"attribution": "execweave_gateway_cli",
|
|
347
|
+
"attributes": attrs,
|
|
348
|
+
}
|
|
349
|
+
events = [
|
|
350
|
+
_content_event(
|
|
351
|
+
**common,
|
|
352
|
+
value=request_payload,
|
|
353
|
+
content_kind="inference_gateway.openrouter.request",
|
|
354
|
+
relation="OBSERVED_INFERENCE_REQUEST",
|
|
355
|
+
observed_field="request",
|
|
356
|
+
)
|
|
357
|
+
]
|
|
358
|
+
if "messages" in request_payload:
|
|
359
|
+
events.append(
|
|
360
|
+
_content_event(
|
|
361
|
+
**common,
|
|
362
|
+
value=request_payload["messages"],
|
|
363
|
+
content_kind="inference_gateway.openrouter.request_messages",
|
|
364
|
+
relation="OBSERVED_INFERENCE_REQUEST_MESSAGES",
|
|
365
|
+
observed_field="request.messages",
|
|
366
|
+
)
|
|
367
|
+
)
|
|
368
|
+
tool_results = _tool_result_messages(request_payload["messages"])
|
|
369
|
+
if tool_results:
|
|
370
|
+
events.append(
|
|
371
|
+
_content_event(
|
|
372
|
+
**common,
|
|
373
|
+
value=tool_results,
|
|
374
|
+
content_kind="inference_gateway.openrouter.tool_result_messages",
|
|
375
|
+
relation="OBSERVED_TOOL_RESULT_MESSAGES",
|
|
376
|
+
observed_field="request.messages[role=tool|function]",
|
|
377
|
+
)
|
|
378
|
+
)
|
|
379
|
+
if "tools" in request_payload:
|
|
380
|
+
events.append(
|
|
381
|
+
_content_event(
|
|
382
|
+
**common,
|
|
383
|
+
value=request_payload["tools"],
|
|
384
|
+
content_kind="inference_gateway.openrouter.tool_definitions",
|
|
385
|
+
relation="OBSERVED_TOOL_DEFINITIONS",
|
|
386
|
+
observed_field="request.tools",
|
|
387
|
+
)
|
|
388
|
+
)
|
|
389
|
+
for event in gateway_response_to_content_events(
|
|
390
|
+
response_payload,
|
|
391
|
+
store=store,
|
|
392
|
+
gateway_name="openrouter",
|
|
393
|
+
endpoint=safe_endpoint,
|
|
394
|
+
request_id=request_id,
|
|
395
|
+
timestamp=observed_at,
|
|
396
|
+
provider_name=provider_name,
|
|
397
|
+
deployment_id=deployment_id,
|
|
398
|
+
):
|
|
399
|
+
if event.get("relation") == "OBSERVED_PROVIDER_METADATA":
|
|
400
|
+
continue
|
|
401
|
+
event["attributes"].update(attrs)
|
|
402
|
+
event["attributes"]["evidence_source"] = "caller_supplied_exchange"
|
|
403
|
+
event["attributes"]["attribution"] = "execweave_gateway_cli"
|
|
404
|
+
events.append(event)
|
|
405
|
+
metadata: dict[str, Any] = {
|
|
406
|
+
"gateway": "openrouter",
|
|
407
|
+
"endpoint": safe_endpoint,
|
|
408
|
+
"request_id": request["name"],
|
|
409
|
+
"requested_model": request_payload.get("model"),
|
|
410
|
+
"resolved_model": response_payload.get("model"),
|
|
411
|
+
}
|
|
412
|
+
if provider_name:
|
|
413
|
+
metadata["provider_name"] = provider_name
|
|
414
|
+
if deployment_id:
|
|
415
|
+
metadata["deployment_id"] = deployment_id
|
|
416
|
+
metadata_event = _metadata_event(
|
|
417
|
+
metadata=metadata,
|
|
418
|
+
store=store,
|
|
419
|
+
timestamp=observed_at,
|
|
420
|
+
provider="openrouter",
|
|
421
|
+
source=request,
|
|
422
|
+
evidence_source="caller_supplied_exchange",
|
|
423
|
+
attribution="execweave_gateway_cli",
|
|
424
|
+
content_kind="inference_gateway.openrouter.provider_metadata",
|
|
425
|
+
observed_field="integration_metadata",
|
|
426
|
+
attributes=attrs,
|
|
427
|
+
)
|
|
428
|
+
if metadata_event is not None:
|
|
429
|
+
events.append(metadata_event)
|
|
430
|
+
return events
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
def _litellm_tools(
|
|
434
|
+
callback_kwargs: dict[str, Any], standard: dict[str, Any]
|
|
435
|
+
) -> list[tuple[str, Any]]:
|
|
436
|
+
values: list[tuple[str, Any]] = []
|
|
437
|
+
if "tools" in callback_kwargs:
|
|
438
|
+
values.append(("kwargs.tools", callback_kwargs["tools"]))
|
|
439
|
+
optional = callback_kwargs.get("optional_params")
|
|
440
|
+
if isinstance(optional, dict) and "tools" in optional:
|
|
441
|
+
values.append(("kwargs.optional_params.tools", optional["tools"]))
|
|
442
|
+
model_parameters = standard.get("model_parameters")
|
|
443
|
+
if isinstance(model_parameters, dict) and "tools" in model_parameters:
|
|
444
|
+
values.append(("standard_logging_object.model_parameters.tools", model_parameters["tools"]))
|
|
445
|
+
return values
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
def litellm_callback_to_content_events(
|
|
449
|
+
callback_kwargs: dict[str, Any],
|
|
450
|
+
response_obj: Any,
|
|
451
|
+
*,
|
|
452
|
+
store: FullFidelityContentStore,
|
|
453
|
+
endpoint: str = "http://localhost:4000",
|
|
454
|
+
timestamp: str | None = None,
|
|
455
|
+
) -> list[dict[str, Any]]:
|
|
456
|
+
"""Store complete content exposed by LiteLLM's success callback, fail-open at caller."""
|
|
457
|
+
standard = callback_kwargs.get("standard_logging_object")
|
|
458
|
+
if not isinstance(standard, dict):
|
|
459
|
+
raise ValueError("LiteLLM callback requires standard_logging_object")
|
|
460
|
+
call_id = standard.get("id")
|
|
461
|
+
if not isinstance(call_id, str) or not call_id:
|
|
462
|
+
raise ValueError("LiteLLM standard logging payload requires id")
|
|
463
|
+
observed_at = timestamp or _now()
|
|
464
|
+
safe_endpoint = sanitize_gateway_endpoint(endpoint)
|
|
465
|
+
response = response_obj if isinstance(response_obj, dict) else None
|
|
466
|
+
identity = response or {
|
|
467
|
+
"id": call_id,
|
|
468
|
+
"model": standard.get("model"),
|
|
469
|
+
"usage": {"total_tokens": standard.get("total_tokens")},
|
|
470
|
+
}
|
|
471
|
+
request = _request_entity("litellm", identity, endpoint=safe_endpoint, request_id=call_id)
|
|
472
|
+
attrs = {
|
|
473
|
+
"observation_scope": "litellm_success_callback",
|
|
474
|
+
"automatic_callback_observation": True,
|
|
475
|
+
"wire_interception_asserted": False,
|
|
476
|
+
}
|
|
477
|
+
common = {
|
|
478
|
+
"store": store,
|
|
479
|
+
"timestamp": observed_at,
|
|
480
|
+
"provider": "litellm",
|
|
481
|
+
"source": request,
|
|
482
|
+
"evidence_source": "litellm_callback",
|
|
483
|
+
"attribution": "litellm_success_callback",
|
|
484
|
+
"attributes": attrs,
|
|
485
|
+
}
|
|
486
|
+
events: list[dict[str, Any]] = []
|
|
487
|
+
for field in ("prompt", "input"):
|
|
488
|
+
value = callback_kwargs.get(field)
|
|
489
|
+
observed_field = f"kwargs.{field}"
|
|
490
|
+
if value is None:
|
|
491
|
+
value = standard.get(field)
|
|
492
|
+
observed_field = f"standard_logging_object.{field}"
|
|
493
|
+
if value is not None:
|
|
494
|
+
events.append(
|
|
495
|
+
_content_event(
|
|
496
|
+
**common,
|
|
497
|
+
value=value,
|
|
498
|
+
content_kind=f"inference_gateway.litellm.request_{field}",
|
|
499
|
+
relation=(
|
|
500
|
+
"OBSERVED_INFERENCE_REQUEST_PROMPT"
|
|
501
|
+
if field == "prompt"
|
|
502
|
+
else "OBSERVED_INFERENCE_REQUEST_INPUT"
|
|
503
|
+
),
|
|
504
|
+
observed_field=observed_field,
|
|
505
|
+
)
|
|
506
|
+
)
|
|
507
|
+
messages = callback_kwargs.get("messages")
|
|
508
|
+
message_field = "kwargs.messages"
|
|
509
|
+
if messages is None:
|
|
510
|
+
messages = standard.get("messages")
|
|
511
|
+
message_field = "standard_logging_object.messages"
|
|
512
|
+
if messages is not None:
|
|
513
|
+
events.append(
|
|
514
|
+
_content_event(
|
|
515
|
+
**common,
|
|
516
|
+
value=messages,
|
|
517
|
+
content_kind="inference_gateway.litellm.request_messages",
|
|
518
|
+
relation="OBSERVED_INFERENCE_REQUEST_MESSAGES",
|
|
519
|
+
observed_field=message_field,
|
|
520
|
+
)
|
|
521
|
+
)
|
|
522
|
+
tool_results = _tool_result_messages(messages)
|
|
523
|
+
if tool_results:
|
|
524
|
+
events.append(
|
|
525
|
+
_content_event(
|
|
526
|
+
**common,
|
|
527
|
+
value=tool_results,
|
|
528
|
+
content_kind="inference_gateway.litellm.tool_result_messages",
|
|
529
|
+
relation="OBSERVED_TOOL_RESULT_MESSAGES",
|
|
530
|
+
observed_field=f"{message_field}[role=tool|function]",
|
|
531
|
+
)
|
|
532
|
+
)
|
|
533
|
+
for observed_field, tools in _litellm_tools(callback_kwargs, standard):
|
|
534
|
+
events.append(
|
|
535
|
+
_content_event(
|
|
536
|
+
**common,
|
|
537
|
+
value=tools,
|
|
538
|
+
content_kind="inference_gateway.litellm.tool_definitions",
|
|
539
|
+
relation="OBSERVED_TOOL_DEFINITIONS",
|
|
540
|
+
observed_field=observed_field,
|
|
541
|
+
)
|
|
542
|
+
)
|
|
543
|
+
for observed_field, config in (
|
|
544
|
+
("kwargs.optional_params", callback_kwargs.get("optional_params")),
|
|
545
|
+
("standard_logging_object.model_parameters", standard.get("model_parameters")),
|
|
546
|
+
):
|
|
547
|
+
if not isinstance(config, dict):
|
|
548
|
+
continue
|
|
549
|
+
event = _metadata_event(
|
|
550
|
+
metadata=config,
|
|
551
|
+
store=store,
|
|
552
|
+
timestamp=observed_at,
|
|
553
|
+
provider="litellm",
|
|
554
|
+
source=request,
|
|
555
|
+
evidence_source="litellm_callback",
|
|
556
|
+
attribution="litellm_success_callback",
|
|
557
|
+
content_kind="inference_gateway.litellm.provider_request_config",
|
|
558
|
+
observed_field=observed_field,
|
|
559
|
+
attributes={**attrs, "provider_facing_request_config": True},
|
|
560
|
+
)
|
|
561
|
+
if event is not None:
|
|
562
|
+
event["relation"] = "OBSERVED_PROVIDER_REQUEST_CONFIG"
|
|
563
|
+
events.append(event)
|
|
564
|
+
if response is not None:
|
|
565
|
+
events.append(
|
|
566
|
+
_content_event(
|
|
567
|
+
**common,
|
|
568
|
+
value=response,
|
|
569
|
+
content_kind="inference_gateway.litellm.response_object",
|
|
570
|
+
relation="OBSERVED_INFERENCE_RESPONSE",
|
|
571
|
+
observed_field="response_obj",
|
|
572
|
+
)
|
|
573
|
+
)
|
|
574
|
+
tool_calls = _response_tool_calls(response)
|
|
575
|
+
if tool_calls:
|
|
576
|
+
events.append(
|
|
577
|
+
_content_event(
|
|
578
|
+
**common,
|
|
579
|
+
value=tool_calls,
|
|
580
|
+
content_kind="inference_gateway.litellm.assistant_tool_calls",
|
|
581
|
+
relation="OBSERVED_ASSISTANT_TOOL_CALLS",
|
|
582
|
+
observed_field="response_obj.tool_calls",
|
|
583
|
+
)
|
|
584
|
+
)
|
|
585
|
+
if standard.get("response") is not None:
|
|
586
|
+
events.append(
|
|
587
|
+
_content_event(
|
|
588
|
+
**common,
|
|
589
|
+
value=standard["response"],
|
|
590
|
+
content_kind="inference_gateway.litellm.standard_logging_response",
|
|
591
|
+
relation="OBSERVED_STANDARD_LOGGING_RESPONSE",
|
|
592
|
+
observed_field="standard_logging_object.response",
|
|
593
|
+
)
|
|
594
|
+
)
|
|
595
|
+
metadata = {key: value for key, value in standard.items() if key not in _CONTENT_FIELDS}
|
|
596
|
+
if callback_kwargs.get("litellm_params") is not None:
|
|
597
|
+
metadata["callback_litellm_params"] = callback_kwargs["litellm_params"]
|
|
598
|
+
metadata["gateway_endpoint"] = safe_endpoint
|
|
599
|
+
event = _metadata_event(
|
|
600
|
+
metadata=metadata,
|
|
601
|
+
store=store,
|
|
602
|
+
timestamp=observed_at,
|
|
603
|
+
provider="litellm",
|
|
604
|
+
source=request,
|
|
605
|
+
evidence_source="litellm_callback",
|
|
606
|
+
attribution="litellm_success_callback",
|
|
607
|
+
content_kind="inference_gateway.litellm.provider_metadata",
|
|
608
|
+
observed_field="standard_logging_object.metadata_projection",
|
|
609
|
+
attributes=attrs,
|
|
610
|
+
)
|
|
611
|
+
if event is not None:
|
|
612
|
+
events.append(event)
|
|
613
|
+
return events
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
from datetime import datetime, timezone
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _now() -> str:
|
|
9
|
+
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _entity(
|
|
13
|
+
entity_type: str,
|
|
14
|
+
entity_id: str,
|
|
15
|
+
*,
|
|
16
|
+
name: str | None = None,
|
|
17
|
+
attributes: dict[str, Any] | None = None,
|
|
18
|
+
) -> dict[str, Any]:
|
|
19
|
+
return {"type": entity_type, "id": entity_id, "name": name, "attributes": attributes or {}}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _required(value: str, *, field: str) -> str:
|
|
23
|
+
if not isinstance(value, str) or not value.strip():
|
|
24
|
+
raise ValueError(f"{field} must be a non-empty string")
|
|
25
|
+
return value
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def gateway_runtime_identity_event(
|
|
29
|
+
*,
|
|
30
|
+
gateway: str,
|
|
31
|
+
gateway_request_id: str,
|
|
32
|
+
runtime: str,
|
|
33
|
+
runtime_request_id: str,
|
|
34
|
+
shared_request_id: str,
|
|
35
|
+
timestamp: str | None = None,
|
|
36
|
+
) -> dict[str, Any]:
|
|
37
|
+
gateway = _required(gateway, field="gateway")
|
|
38
|
+
gateway_request_id = _required(gateway_request_id, field="gateway_request_id")
|
|
39
|
+
runtime = _required(runtime, field="runtime")
|
|
40
|
+
runtime_request_id = _required(runtime_request_id, field="runtime_request_id")
|
|
41
|
+
shared_request_id = _required(shared_request_id, field="shared_request_id")
|
|
42
|
+
|
|
43
|
+
shared_hash = hashlib.sha256(
|
|
44
|
+
shared_request_id.encode("utf-8", errors="replace")
|
|
45
|
+
).hexdigest()[:32]
|
|
46
|
+
source = _entity(
|
|
47
|
+
"inference_request",
|
|
48
|
+
f"inference-request:{gateway}:{gateway_request_id}",
|
|
49
|
+
name=gateway_request_id,
|
|
50
|
+
attributes={"gateway": gateway},
|
|
51
|
+
)
|
|
52
|
+
target = _entity(
|
|
53
|
+
"inference_request",
|
|
54
|
+
f"inference-request:{runtime}:{runtime_request_id}",
|
|
55
|
+
name=runtime_request_id,
|
|
56
|
+
attributes={"provider": runtime},
|
|
57
|
+
)
|
|
58
|
+
return {
|
|
59
|
+
"timestamp": timestamp or _now(),
|
|
60
|
+
"event_type": "inference_identity.gateway_runtime.exact",
|
|
61
|
+
"relation": "SAME_INFERENCE_REQUEST",
|
|
62
|
+
"source": source,
|
|
63
|
+
"target": target,
|
|
64
|
+
"attributes": {
|
|
65
|
+
"backend": "cross_layer_identity",
|
|
66
|
+
"attribution": "explicit_shared_request_id",
|
|
67
|
+
"evidence_source": "caller_supplied_shared_request_id",
|
|
68
|
+
"gateway": gateway,
|
|
69
|
+
"runtime": runtime,
|
|
70
|
+
"causal": False,
|
|
71
|
+
"inferred": False,
|
|
72
|
+
"identity_exact": True,
|
|
73
|
+
"identity_method": "shared_request_id",
|
|
74
|
+
"shared_request_id_hash": shared_hash,
|
|
75
|
+
},
|
|
76
|
+
}
|