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,189 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
from datetime import datetime, timezone
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from .content_store import FullFidelityContentStore
|
|
11
|
+
from .privacy import full_content_capture_enabled
|
|
12
|
+
from .openai_compatible import (
|
|
13
|
+
append_openai_compatible_records,
|
|
14
|
+
response_to_events,
|
|
15
|
+
sanitize_openai_compatible_endpoint,
|
|
16
|
+
)
|
|
17
|
+
from .openai_compatible_full_fidelity import (
|
|
18
|
+
exchange_to_content_events,
|
|
19
|
+
response_to_content_events,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _now() -> str:
|
|
24
|
+
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _sidecar(value: Path | None) -> Path:
|
|
28
|
+
if value is not None:
|
|
29
|
+
return value
|
|
30
|
+
configured = os.environ.get("EXECWEAVE_SEMANTIC_SIDECAR")
|
|
31
|
+
if configured:
|
|
32
|
+
return Path(configured)
|
|
33
|
+
raise ValueError("--sidecar or EXECWEAVE_SEMANTIC_SIDECAR is required")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _read_json_stdin() -> dict:
|
|
37
|
+
raw = sys.stdin.read()
|
|
38
|
+
if not raw.strip():
|
|
39
|
+
raise ValueError("stdin is empty")
|
|
40
|
+
try:
|
|
41
|
+
payload = json.loads(raw)
|
|
42
|
+
except json.JSONDecodeError as exc:
|
|
43
|
+
raise ValueError(f"stdin is invalid JSON: {exc.msg}") from exc
|
|
44
|
+
if not isinstance(payload, dict):
|
|
45
|
+
raise ValueError("stdin must contain one JSON object")
|
|
46
|
+
return payload
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
50
|
+
parser = argparse.ArgumentParser(
|
|
51
|
+
prog="execweave-openai-compatible",
|
|
52
|
+
description=(
|
|
53
|
+
"Capture explicit OpenAI-compatible direct API evidence plus complete content "
|
|
54
|
+
"exposed by the selected integration point."
|
|
55
|
+
),
|
|
56
|
+
)
|
|
57
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
58
|
+
|
|
59
|
+
event = sub.add_parser(
|
|
60
|
+
"event",
|
|
61
|
+
help="Capture one supplied final API response; this is response-only evidence.",
|
|
62
|
+
)
|
|
63
|
+
event.add_argument("--endpoint", required=True)
|
|
64
|
+
event.add_argument("--provider-name", default="openai-compatible")
|
|
65
|
+
event.add_argument("--request-id", default=None)
|
|
66
|
+
event.add_argument("--sidecar", type=Path, default=None)
|
|
67
|
+
|
|
68
|
+
exchange = sub.add_parser(
|
|
69
|
+
"exchange",
|
|
70
|
+
help=(
|
|
71
|
+
"Capture caller-supplied request+response JSON; this does not assert transparent "
|
|
72
|
+
"interception."
|
|
73
|
+
),
|
|
74
|
+
)
|
|
75
|
+
exchange.add_argument("--endpoint", required=True)
|
|
76
|
+
exchange.add_argument("--provider-name", default="openai-compatible")
|
|
77
|
+
exchange.add_argument("--request-id", default=None)
|
|
78
|
+
exchange.add_argument("--sidecar", type=Path, default=None)
|
|
79
|
+
return parser
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _append_full_fidelity_fail_open(sidecar: Path, records_factory) -> int:
|
|
83
|
+
if not full_content_capture_enabled():
|
|
84
|
+
return 0
|
|
85
|
+
try:
|
|
86
|
+
records = records_factory(FullFidelityContentStore(sidecar.parent))
|
|
87
|
+
append_openai_compatible_records(sidecar, records)
|
|
88
|
+
return len(records)
|
|
89
|
+
except (OSError, RuntimeError, TimeoutError, TypeError, ValueError) as exc:
|
|
90
|
+
print(f"ExecWeave OpenAI-compatible full-fidelity warning: {exc}", file=sys.stderr)
|
|
91
|
+
return 0
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _event_command(args: argparse.Namespace) -> int:
|
|
95
|
+
payload = _read_json_stdin()
|
|
96
|
+
endpoint = sanitize_openai_compatible_endpoint(args.endpoint)
|
|
97
|
+
sidecar = _sidecar(args.sidecar).expanduser().resolve()
|
|
98
|
+
observed_at = _now()
|
|
99
|
+
records = response_to_events(
|
|
100
|
+
payload,
|
|
101
|
+
endpoint=endpoint,
|
|
102
|
+
provider_name=args.provider_name,
|
|
103
|
+
request_id=args.request_id,
|
|
104
|
+
timestamp=observed_at,
|
|
105
|
+
)
|
|
106
|
+
output = append_openai_compatible_records(sidecar, records)
|
|
107
|
+
full_records = _append_full_fidelity_fail_open(
|
|
108
|
+
sidecar,
|
|
109
|
+
lambda store: response_to_content_events(
|
|
110
|
+
payload,
|
|
111
|
+
store=store,
|
|
112
|
+
endpoint=endpoint,
|
|
113
|
+
provider_name=args.provider_name,
|
|
114
|
+
request_id=args.request_id,
|
|
115
|
+
timestamp=observed_at,
|
|
116
|
+
),
|
|
117
|
+
)
|
|
118
|
+
print(
|
|
119
|
+
json.dumps(
|
|
120
|
+
{
|
|
121
|
+
"full_fidelity_records": full_records,
|
|
122
|
+
"records": len(records),
|
|
123
|
+
"sidecar": str(output),
|
|
124
|
+
},
|
|
125
|
+
sort_keys=True,
|
|
126
|
+
)
|
|
127
|
+
)
|
|
128
|
+
return 0
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _exchange_command(args: argparse.Namespace) -> int:
|
|
132
|
+
exchange = _read_json_stdin()
|
|
133
|
+
request_payload = exchange.get("request")
|
|
134
|
+
response_payload = exchange.get("response")
|
|
135
|
+
if not isinstance(request_payload, dict) or not isinstance(response_payload, dict):
|
|
136
|
+
raise ValueError("exchange stdin requires JSON-object request and response fields")
|
|
137
|
+
endpoint = sanitize_openai_compatible_endpoint(args.endpoint)
|
|
138
|
+
sidecar = _sidecar(args.sidecar).expanduser().resolve()
|
|
139
|
+
observed_at = _now()
|
|
140
|
+
requested_model = request_payload.get("model")
|
|
141
|
+
if not isinstance(requested_model, str) or not requested_model:
|
|
142
|
+
requested_model = None
|
|
143
|
+
records = response_to_events(
|
|
144
|
+
response_payload,
|
|
145
|
+
endpoint=endpoint,
|
|
146
|
+
provider_name=args.provider_name,
|
|
147
|
+
requested_model=requested_model,
|
|
148
|
+
request_id=args.request_id,
|
|
149
|
+
timestamp=observed_at,
|
|
150
|
+
)
|
|
151
|
+
output = append_openai_compatible_records(sidecar, records)
|
|
152
|
+
full_records = _append_full_fidelity_fail_open(
|
|
153
|
+
sidecar,
|
|
154
|
+
lambda store: exchange_to_content_events(
|
|
155
|
+
exchange,
|
|
156
|
+
store=store,
|
|
157
|
+
endpoint=endpoint,
|
|
158
|
+
provider_name=args.provider_name,
|
|
159
|
+
request_id=args.request_id,
|
|
160
|
+
timestamp=observed_at,
|
|
161
|
+
),
|
|
162
|
+
)
|
|
163
|
+
print(
|
|
164
|
+
json.dumps(
|
|
165
|
+
{
|
|
166
|
+
"full_fidelity_records": full_records,
|
|
167
|
+
"records": len(records),
|
|
168
|
+
"sidecar": str(output),
|
|
169
|
+
},
|
|
170
|
+
sort_keys=True,
|
|
171
|
+
)
|
|
172
|
+
)
|
|
173
|
+
return 0
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def main(argv: list[str] | None = None) -> int:
|
|
177
|
+
parser = build_parser()
|
|
178
|
+
args = parser.parse_args(argv)
|
|
179
|
+
try:
|
|
180
|
+
if args.command == "event":
|
|
181
|
+
return _event_command(args)
|
|
182
|
+
return _exchange_command(args)
|
|
183
|
+
except (OSError, TimeoutError, ValueError) as exc:
|
|
184
|
+
parser.error(str(exc))
|
|
185
|
+
return 2
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
if __name__ == "__main__":
|
|
189
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import replace
|
|
4
|
+
from datetime import datetime, timezone
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from .content_evidence import content_observation_event
|
|
8
|
+
from .content_store import ContentReference, FullFidelityContentStore
|
|
9
|
+
from .openai_compatible import (
|
|
10
|
+
_endpoint_digest,
|
|
11
|
+
_request_identity,
|
|
12
|
+
sanitize_openai_compatible_endpoint,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
_REQUEST_CONTENT_KEYS = frozenset(
|
|
16
|
+
{"messages", "prompt", "input", "system", "instructions", "tools", "functions"}
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _now() -> str:
|
|
21
|
+
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _request_entity(
|
|
25
|
+
response: dict[str, Any],
|
|
26
|
+
*,
|
|
27
|
+
endpoint: str,
|
|
28
|
+
provider_name: str,
|
|
29
|
+
request_id: str | None,
|
|
30
|
+
observed_at: str,
|
|
31
|
+
) -> dict[str, Any]:
|
|
32
|
+
safe_endpoint = sanitize_openai_compatible_endpoint(endpoint)
|
|
33
|
+
endpoint_scope = _endpoint_digest(safe_endpoint)
|
|
34
|
+
native_id, request_id_source = _request_identity(
|
|
35
|
+
response,
|
|
36
|
+
request_id,
|
|
37
|
+
endpoint_scope=endpoint_scope,
|
|
38
|
+
observed_at=observed_at,
|
|
39
|
+
)
|
|
40
|
+
return {
|
|
41
|
+
"type": "inference_request",
|
|
42
|
+
"id": f"inference-request:openai-compatible:{endpoint_scope}:{native_id}",
|
|
43
|
+
"name": native_id,
|
|
44
|
+
"attributes": {
|
|
45
|
+
"protocol": "openai_compatible",
|
|
46
|
+
"provider_name": provider_name,
|
|
47
|
+
"endpoint": safe_endpoint,
|
|
48
|
+
"endpoint_scope": endpoint_scope,
|
|
49
|
+
"request_id_source": request_id_source,
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _store(
|
|
55
|
+
store: FullFidelityContentStore,
|
|
56
|
+
value: Any,
|
|
57
|
+
*,
|
|
58
|
+
content_kind: str,
|
|
59
|
+
) -> ContentReference:
|
|
60
|
+
if isinstance(value, str):
|
|
61
|
+
return store.put_text(value, content_kind=content_kind)
|
|
62
|
+
return store.put_json(value, content_kind=content_kind)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _content_event(
|
|
66
|
+
*,
|
|
67
|
+
store: FullFidelityContentStore,
|
|
68
|
+
value: Any,
|
|
69
|
+
content_kind: str,
|
|
70
|
+
timestamp: str,
|
|
71
|
+
provider_name: str,
|
|
72
|
+
source: dict[str, Any],
|
|
73
|
+
relation: str,
|
|
74
|
+
observed_field: str,
|
|
75
|
+
evidence_source: str,
|
|
76
|
+
attribution: str,
|
|
77
|
+
attributes: dict[str, Any],
|
|
78
|
+
) -> dict[str, Any]:
|
|
79
|
+
return content_observation_event(
|
|
80
|
+
timestamp=timestamp,
|
|
81
|
+
provider=provider_name,
|
|
82
|
+
source=source,
|
|
83
|
+
reference=_store(store, value, content_kind=content_kind),
|
|
84
|
+
relation=relation,
|
|
85
|
+
observed_field=observed_field,
|
|
86
|
+
evidence_source=evidence_source,
|
|
87
|
+
attribution=attribution,
|
|
88
|
+
event_type="openai_compatible.content.observed",
|
|
89
|
+
attributes=attributes,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _metadata_event(
|
|
94
|
+
*,
|
|
95
|
+
store: FullFidelityContentStore,
|
|
96
|
+
metadata: dict[str, Any],
|
|
97
|
+
timestamp: str,
|
|
98
|
+
provider_name: str,
|
|
99
|
+
source: dict[str, Any],
|
|
100
|
+
evidence_source: str,
|
|
101
|
+
attribution: str,
|
|
102
|
+
attributes: dict[str, Any],
|
|
103
|
+
) -> dict[str, Any]:
|
|
104
|
+
reference = store.put_json(metadata, content_kind="openai_compatible.provider_metadata")
|
|
105
|
+
reference = replace(reference, complete_from_source=False)
|
|
106
|
+
return content_observation_event(
|
|
107
|
+
timestamp=timestamp,
|
|
108
|
+
provider=provider_name,
|
|
109
|
+
source=source,
|
|
110
|
+
reference=reference,
|
|
111
|
+
relation="OBSERVED_PROVIDER_METADATA",
|
|
112
|
+
observed_field="integration_metadata_projection",
|
|
113
|
+
evidence_source=evidence_source,
|
|
114
|
+
attribution=attribution,
|
|
115
|
+
event_type="openai_compatible.metadata.observed",
|
|
116
|
+
attributes={
|
|
117
|
+
**attributes,
|
|
118
|
+
"metadata_projection": True,
|
|
119
|
+
"metadata_complete_from_source": False,
|
|
120
|
+
},
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _assistant_messages(response: object) -> list[Any]:
|
|
125
|
+
if not isinstance(response, dict):
|
|
126
|
+
return []
|
|
127
|
+
messages: list[Any] = []
|
|
128
|
+
native = response.get("message")
|
|
129
|
+
if isinstance(native, dict):
|
|
130
|
+
messages.append(native)
|
|
131
|
+
choices = response.get("choices")
|
|
132
|
+
if isinstance(choices, list):
|
|
133
|
+
for choice in choices:
|
|
134
|
+
if isinstance(choice, dict) and isinstance(choice.get("message"), dict):
|
|
135
|
+
messages.append(choice["message"])
|
|
136
|
+
output = response.get("output")
|
|
137
|
+
if isinstance(output, list):
|
|
138
|
+
for item in output:
|
|
139
|
+
if isinstance(item, dict) and item.get("type") in {"message", "assistant_message"}:
|
|
140
|
+
messages.append(item)
|
|
141
|
+
return messages
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _response_tool_calls(response: object) -> list[Any]:
|
|
145
|
+
if not isinstance(response, dict):
|
|
146
|
+
return []
|
|
147
|
+
calls: list[Any] = []
|
|
148
|
+
direct = response.get("tool_calls")
|
|
149
|
+
if isinstance(direct, list):
|
|
150
|
+
calls.extend(direct)
|
|
151
|
+
for message in _assistant_messages(response):
|
|
152
|
+
if isinstance(message, dict):
|
|
153
|
+
nested = message.get("tool_calls")
|
|
154
|
+
if isinstance(nested, list):
|
|
155
|
+
calls.extend(nested)
|
|
156
|
+
output = response.get("output")
|
|
157
|
+
if isinstance(output, list):
|
|
158
|
+
for item in output:
|
|
159
|
+
if not isinstance(item, dict):
|
|
160
|
+
continue
|
|
161
|
+
if item.get("type") in {"function_call", "tool_call", "tool_use"}:
|
|
162
|
+
calls.append(item)
|
|
163
|
+
nested = item.get("tool_calls")
|
|
164
|
+
if isinstance(nested, list):
|
|
165
|
+
calls.extend(nested)
|
|
166
|
+
return calls
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _tool_results(request: dict[str, Any]) -> list[Any]:
|
|
170
|
+
results: list[Any] = []
|
|
171
|
+
messages = request.get("messages")
|
|
172
|
+
if isinstance(messages, list):
|
|
173
|
+
results.extend(
|
|
174
|
+
item
|
|
175
|
+
for item in messages
|
|
176
|
+
if isinstance(item, dict) and item.get("role") in {"tool", "function"}
|
|
177
|
+
)
|
|
178
|
+
input_value = request.get("input")
|
|
179
|
+
if isinstance(input_value, list):
|
|
180
|
+
results.extend(
|
|
181
|
+
item
|
|
182
|
+
for item in input_value
|
|
183
|
+
if isinstance(item, dict)
|
|
184
|
+
and item.get("type") in {"function_call_output", "tool_result", "tool_output"}
|
|
185
|
+
)
|
|
186
|
+
return results
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def response_to_content_events(
|
|
190
|
+
payload: dict[str, Any],
|
|
191
|
+
*,
|
|
192
|
+
store: FullFidelityContentStore,
|
|
193
|
+
endpoint: str,
|
|
194
|
+
provider_name: str = "openai-compatible",
|
|
195
|
+
request_id: str | None = None,
|
|
196
|
+
timestamp: str | None = None,
|
|
197
|
+
) -> list[dict[str, Any]]:
|
|
198
|
+
"""Store the complete supplied final response without claiming request visibility."""
|
|
199
|
+
observed_at = timestamp or _now()
|
|
200
|
+
safe_endpoint = sanitize_openai_compatible_endpoint(endpoint)
|
|
201
|
+
request = _request_entity(
|
|
202
|
+
payload,
|
|
203
|
+
endpoint=safe_endpoint,
|
|
204
|
+
provider_name=provider_name,
|
|
205
|
+
request_id=request_id,
|
|
206
|
+
observed_at=observed_at,
|
|
207
|
+
)
|
|
208
|
+
attrs = {
|
|
209
|
+
"observation_scope": "response_only",
|
|
210
|
+
"request_observed": False,
|
|
211
|
+
"caller_supplied_exchange": False,
|
|
212
|
+
"wire_interception_asserted": False,
|
|
213
|
+
"streaming_chunks_observed": False,
|
|
214
|
+
}
|
|
215
|
+
common = {
|
|
216
|
+
"store": store,
|
|
217
|
+
"timestamp": observed_at,
|
|
218
|
+
"provider_name": provider_name,
|
|
219
|
+
"source": request,
|
|
220
|
+
"evidence_source": "openai_compatible_response",
|
|
221
|
+
"attribution": "direct_api_response",
|
|
222
|
+
"attributes": attrs,
|
|
223
|
+
}
|
|
224
|
+
events = [
|
|
225
|
+
_content_event(
|
|
226
|
+
**common,
|
|
227
|
+
value=payload,
|
|
228
|
+
content_kind="openai_compatible.response",
|
|
229
|
+
relation="OBSERVED_INFERENCE_RESPONSE",
|
|
230
|
+
observed_field="response",
|
|
231
|
+
)
|
|
232
|
+
]
|
|
233
|
+
assistant_messages = _assistant_messages(payload)
|
|
234
|
+
if assistant_messages:
|
|
235
|
+
events.append(
|
|
236
|
+
_content_event(
|
|
237
|
+
**common,
|
|
238
|
+
value=assistant_messages,
|
|
239
|
+
content_kind="openai_compatible.assistant_messages",
|
|
240
|
+
relation="OBSERVED_ASSISTANT_MESSAGES",
|
|
241
|
+
observed_field="response.assistant_messages",
|
|
242
|
+
)
|
|
243
|
+
)
|
|
244
|
+
tool_calls = _response_tool_calls(payload)
|
|
245
|
+
if tool_calls:
|
|
246
|
+
events.append(
|
|
247
|
+
_content_event(
|
|
248
|
+
**common,
|
|
249
|
+
value=tool_calls,
|
|
250
|
+
content_kind="openai_compatible.assistant_tool_calls",
|
|
251
|
+
relation="OBSERVED_ASSISTANT_TOOL_CALLS",
|
|
252
|
+
observed_field="response.tool_calls",
|
|
253
|
+
)
|
|
254
|
+
)
|
|
255
|
+
metadata = {
|
|
256
|
+
"protocol": "openai_compatible",
|
|
257
|
+
"provider_name": provider_name,
|
|
258
|
+
"endpoint": safe_endpoint,
|
|
259
|
+
"request_id": request["name"],
|
|
260
|
+
"resolved_model": payload.get("model"),
|
|
261
|
+
}
|
|
262
|
+
events.append(
|
|
263
|
+
_metadata_event(
|
|
264
|
+
store=store,
|
|
265
|
+
metadata=metadata,
|
|
266
|
+
timestamp=observed_at,
|
|
267
|
+
provider_name=provider_name,
|
|
268
|
+
source=request,
|
|
269
|
+
evidence_source="openai_compatible_response",
|
|
270
|
+
attribution="direct_api_response",
|
|
271
|
+
attributes=attrs,
|
|
272
|
+
)
|
|
273
|
+
)
|
|
274
|
+
return events
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def exchange_to_content_events(
|
|
278
|
+
exchange: dict[str, Any],
|
|
279
|
+
*,
|
|
280
|
+
store: FullFidelityContentStore,
|
|
281
|
+
endpoint: str,
|
|
282
|
+
provider_name: str = "openai-compatible",
|
|
283
|
+
request_id: str | None = None,
|
|
284
|
+
timestamp: str | None = None,
|
|
285
|
+
) -> list[dict[str, Any]]:
|
|
286
|
+
"""Store caller-supplied request+response evidence; this is not wire interception."""
|
|
287
|
+
request_payload = exchange.get("request")
|
|
288
|
+
response_payload = exchange.get("response")
|
|
289
|
+
if not isinstance(request_payload, dict) or not isinstance(response_payload, dict):
|
|
290
|
+
raise ValueError(
|
|
291
|
+
"OpenAI-compatible exchange requires JSON-object request and response fields"
|
|
292
|
+
)
|
|
293
|
+
stream_chunks = exchange.get("stream_chunks")
|
|
294
|
+
if stream_chunks is not None and not isinstance(stream_chunks, list):
|
|
295
|
+
raise ValueError("OpenAI-compatible stream_chunks must be a JSON array when supplied")
|
|
296
|
+
|
|
297
|
+
observed_at = timestamp or _now()
|
|
298
|
+
safe_endpoint = sanitize_openai_compatible_endpoint(endpoint)
|
|
299
|
+
request = _request_entity(
|
|
300
|
+
response_payload,
|
|
301
|
+
endpoint=safe_endpoint,
|
|
302
|
+
provider_name=provider_name,
|
|
303
|
+
request_id=request_id,
|
|
304
|
+
observed_at=observed_at,
|
|
305
|
+
)
|
|
306
|
+
attrs = {
|
|
307
|
+
"observation_scope": "caller_supplied_exchange",
|
|
308
|
+
"request_observed": True,
|
|
309
|
+
"caller_supplied_exchange": True,
|
|
310
|
+
"wire_interception_asserted": False,
|
|
311
|
+
"streaming_chunks_observed": stream_chunks is not None,
|
|
312
|
+
}
|
|
313
|
+
common = {
|
|
314
|
+
"store": store,
|
|
315
|
+
"timestamp": observed_at,
|
|
316
|
+
"provider_name": provider_name,
|
|
317
|
+
"source": request,
|
|
318
|
+
"evidence_source": "caller_supplied_exchange",
|
|
319
|
+
"attribution": "execweave_openai_compatible_cli",
|
|
320
|
+
"attributes": attrs,
|
|
321
|
+
}
|
|
322
|
+
events = [
|
|
323
|
+
_content_event(
|
|
324
|
+
**common,
|
|
325
|
+
value=request_payload,
|
|
326
|
+
content_kind="openai_compatible.request",
|
|
327
|
+
relation="OBSERVED_INFERENCE_REQUEST",
|
|
328
|
+
observed_field="request",
|
|
329
|
+
)
|
|
330
|
+
]
|
|
331
|
+
for key, relation in (
|
|
332
|
+
("messages", "OBSERVED_INFERENCE_REQUEST_MESSAGES"),
|
|
333
|
+
("prompt", "OBSERVED_INFERENCE_REQUEST_PROMPT"),
|
|
334
|
+
("input", "OBSERVED_INFERENCE_REQUEST_INPUT"),
|
|
335
|
+
):
|
|
336
|
+
if key in request_payload:
|
|
337
|
+
events.append(
|
|
338
|
+
_content_event(
|
|
339
|
+
**common,
|
|
340
|
+
value=request_payload[key],
|
|
341
|
+
content_kind=f"openai_compatible.request_{key}",
|
|
342
|
+
relation=relation,
|
|
343
|
+
observed_field=f"request.{key}",
|
|
344
|
+
)
|
|
345
|
+
)
|
|
346
|
+
for key in ("system", "instructions"):
|
|
347
|
+
if key in request_payload:
|
|
348
|
+
events.append(
|
|
349
|
+
_content_event(
|
|
350
|
+
**common,
|
|
351
|
+
value=request_payload[key],
|
|
352
|
+
content_kind=f"openai_compatible.{key}_context",
|
|
353
|
+
relation="OBSERVED_SYSTEM_CONTEXT",
|
|
354
|
+
observed_field=f"request.{key}",
|
|
355
|
+
)
|
|
356
|
+
)
|
|
357
|
+
for key in ("tools", "functions"):
|
|
358
|
+
if key in request_payload:
|
|
359
|
+
events.append(
|
|
360
|
+
_content_event(
|
|
361
|
+
**common,
|
|
362
|
+
value=request_payload[key],
|
|
363
|
+
content_kind=f"openai_compatible.{key}",
|
|
364
|
+
relation="OBSERVED_TOOL_DEFINITIONS",
|
|
365
|
+
observed_field=f"request.{key}",
|
|
366
|
+
)
|
|
367
|
+
)
|
|
368
|
+
tool_results = _tool_results(request_payload)
|
|
369
|
+
if tool_results:
|
|
370
|
+
events.append(
|
|
371
|
+
_content_event(
|
|
372
|
+
**common,
|
|
373
|
+
value=tool_results,
|
|
374
|
+
content_kind="openai_compatible.tool_results",
|
|
375
|
+
relation="OBSERVED_TOOL_RESULT_MESSAGES",
|
|
376
|
+
observed_field="request.tool_results",
|
|
377
|
+
)
|
|
378
|
+
)
|
|
379
|
+
config = {
|
|
380
|
+
key: value for key, value in request_payload.items() if key not in _REQUEST_CONTENT_KEYS
|
|
381
|
+
}
|
|
382
|
+
if config:
|
|
383
|
+
events.append(
|
|
384
|
+
_content_event(
|
|
385
|
+
**common,
|
|
386
|
+
value=config,
|
|
387
|
+
content_kind="openai_compatible.request_config",
|
|
388
|
+
relation="OBSERVED_PROVIDER_REQUEST_CONFIG",
|
|
389
|
+
observed_field="request.provider_facing_config",
|
|
390
|
+
)
|
|
391
|
+
)
|
|
392
|
+
if stream_chunks is not None:
|
|
393
|
+
events.append(
|
|
394
|
+
_content_event(
|
|
395
|
+
**common,
|
|
396
|
+
value=stream_chunks,
|
|
397
|
+
content_kind="openai_compatible.stream_chunks",
|
|
398
|
+
relation="OBSERVED_INFERENCE_STREAM_CHUNKS",
|
|
399
|
+
observed_field="stream_chunks",
|
|
400
|
+
)
|
|
401
|
+
)
|
|
402
|
+
|
|
403
|
+
for event in response_to_content_events(
|
|
404
|
+
response_payload,
|
|
405
|
+
store=store,
|
|
406
|
+
endpoint=safe_endpoint,
|
|
407
|
+
provider_name=provider_name,
|
|
408
|
+
request_id=request_id,
|
|
409
|
+
timestamp=observed_at,
|
|
410
|
+
):
|
|
411
|
+
if event.get("relation") == "OBSERVED_PROVIDER_METADATA":
|
|
412
|
+
continue
|
|
413
|
+
event["attributes"].update(attrs)
|
|
414
|
+
event["attributes"]["evidence_source"] = "caller_supplied_exchange"
|
|
415
|
+
event["attributes"]["attribution"] = "execweave_openai_compatible_cli"
|
|
416
|
+
events.append(event)
|
|
417
|
+
|
|
418
|
+
metadata = {
|
|
419
|
+
"protocol": "openai_compatible",
|
|
420
|
+
"provider_name": provider_name,
|
|
421
|
+
"endpoint": safe_endpoint,
|
|
422
|
+
"request_id": request["name"],
|
|
423
|
+
"requested_model": request_payload.get("model"),
|
|
424
|
+
"resolved_model": response_payload.get("model"),
|
|
425
|
+
}
|
|
426
|
+
events.append(
|
|
427
|
+
_metadata_event(
|
|
428
|
+
store=store,
|
|
429
|
+
metadata=metadata,
|
|
430
|
+
timestamp=observed_at,
|
|
431
|
+
provider_name=provider_name,
|
|
432
|
+
source=request,
|
|
433
|
+
evidence_source="caller_supplied_exchange",
|
|
434
|
+
attribution="execweave_openai_compatible_cli",
|
|
435
|
+
attributes=attrs,
|
|
436
|
+
)
|
|
437
|
+
)
|
|
438
|
+
return events
|