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,611 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
_STARTUP_SEAM = "applyTheme(initialTheme());applyTransform();poll();"
|
|
4
|
+
|
|
5
|
+
EXECUTION_FLOW_SCRIPT = r"""
|
|
6
|
+
(function(){
|
|
7
|
+
const MODEL_RELATIONS=new Set([
|
|
8
|
+
'USED_MODEL','INVOKED_MODEL','INVOKES_MODEL','INFERRED','SERVED_BY_MODEL',
|
|
9
|
+
'SWITCHED_MODEL','MODEL_INVOCATION_COMPLETED'
|
|
10
|
+
]);
|
|
11
|
+
const DIRECT_ACTION_RELATIONS=new Map([
|
|
12
|
+
['SPAWNED_AGENT','spawn_agent'],
|
|
13
|
+
['SPAWNED_SUBAGENT','spawn_agent'],
|
|
14
|
+
['ASSIGNED_AGENT_TASK','assign_agent_task'],
|
|
15
|
+
['REQUESTED_SUBTASK','assign_agent_task'],
|
|
16
|
+
['SENT_AGENT_MESSAGE','send_input'],
|
|
17
|
+
['CLOSED_AGENT','close_agent'],
|
|
18
|
+
]);
|
|
19
|
+
const ACTION_RELATION=new Map([
|
|
20
|
+
['spawn_agent','SPAWNED_AGENT'],
|
|
21
|
+
['assign_agent_task','ASSIGNED_AGENT_TASK'],
|
|
22
|
+
['send_input','SENT_AGENT_MESSAGE'],
|
|
23
|
+
['wait_agent','WAITED_FOR'],
|
|
24
|
+
['resume_agent','RESUMED_AGENT'],
|
|
25
|
+
['close_agent','CLOSED_AGENT'],
|
|
26
|
+
]);
|
|
27
|
+
const ACTION_ALIASES=new Map([
|
|
28
|
+
['spawn','spawn_agent'],['spawnagent','spawn_agent'],['spawn_agent','spawn_agent'],
|
|
29
|
+
['spawn_subagent','spawn_agent'],['create_agent','spawn_agent'],['create_subagent','spawn_agent'],
|
|
30
|
+
['send','send_input'],['sendinput','send_input'],['send_input','send_input'],
|
|
31
|
+
['sendmessage','send_input'],['send_message','send_input'],['agent_message','send_input'],
|
|
32
|
+
['wait','wait_agent'],['waitagent','wait_agent'],['wait_agent','wait_agent'],
|
|
33
|
+
['wait_for_agent','wait_agent'],['wait_for_agents','wait_agent'],
|
|
34
|
+
['resume','resume_agent'],['resumeagent','resume_agent'],['resume_agent','resume_agent'],
|
|
35
|
+
['close','close_agent'],['closeagent','close_agent'],['close_agent','close_agent'],
|
|
36
|
+
['assign_agent_task','assign_agent_task'],['assign_task','assign_agent_task'],
|
|
37
|
+
['request_subtask','assign_agent_task'],['subtask','assign_agent_task'],
|
|
38
|
+
]);
|
|
39
|
+
const attrsOf=node=>node&&typeof node.attributes==='object'&&node.attributes?node.attributes:{};
|
|
40
|
+
const relation=edge=>String(edge?.relation||'').toUpperCase();
|
|
41
|
+
const actionName=value=>{
|
|
42
|
+
const text=String(value||'').trim().toLowerCase().replace(/[\s-]+/g,'_');
|
|
43
|
+
return ACTION_ALIASES.get(text)||null;
|
|
44
|
+
};
|
|
45
|
+
const moment=item=>{
|
|
46
|
+
const attrs=attrsOf(item);
|
|
47
|
+
const sequence=Number.isInteger(item?.first_sequence)?item.first_sequence
|
|
48
|
+
:(Number.isInteger(attrs.first_sequence)?attrs.first_sequence:null);
|
|
49
|
+
const stamp=item?.first_seen||attrs.first_seen||attrs.timestamp||null;
|
|
50
|
+
return{
|
|
51
|
+
sequence:sequence,
|
|
52
|
+
stamp:stamp?String(stamp):null,
|
|
53
|
+
id:String(item?.id||''),
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
const momentComparable=(left,right)=>{
|
|
57
|
+
if(!left||!right)return false;
|
|
58
|
+
if(left.sequence!==null&&right.sequence!==null)return true;
|
|
59
|
+
if(left.stamp&&right.stamp)return true;
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
const momentLE=(left,right)=>{
|
|
63
|
+
// Only compare when both ends share a sequence or a timestamp. Mixing kinds
|
|
64
|
+
// (or comparing id fallbacks) falsely orders early actions against future switches.
|
|
65
|
+
if(!momentComparable(left,right))return false;
|
|
66
|
+
if(left.sequence!==null&&right.sequence!==null)return left.sequence<=right.sequence;
|
|
67
|
+
return String(left.stamp)<=String(right.stamp);
|
|
68
|
+
};
|
|
69
|
+
const momentEqual=(left,right)=>{
|
|
70
|
+
if(!momentComparable(left,right))return false;
|
|
71
|
+
if(left.sequence!==null&&right.sequence!==null)return left.sequence===right.sequence;
|
|
72
|
+
return String(left.stamp)===String(right.stamp);
|
|
73
|
+
};
|
|
74
|
+
const provider=node=>String(attrsOf(node).provider||'unknown').toLowerCase();
|
|
75
|
+
|
|
76
|
+
function execweaveExecutionFlowProjection(display,raw){
|
|
77
|
+
if(!display||!Array.isArray(display.nodes)||!Array.isArray(display.edges))return display;
|
|
78
|
+
const rawNodes=Array.isArray(raw?.nodes)?raw.nodes:[],rawEdges=Array.isArray(raw?.edges)?raw.edges:[];
|
|
79
|
+
const rawById=new Map(rawNodes.filter(node=>node?.id).map(node=>[node.id,node]));
|
|
80
|
+
const agents=new Map(rawNodes.filter(node=>node?.type==='agent'&&node.id).map(node=>[node.id,node]));
|
|
81
|
+
if(!agents.size)return display;
|
|
82
|
+
const models=new Map(rawNodes.filter(node=>node?.type==='model'&&node.id).map(node=>[node.id,node]));
|
|
83
|
+
|
|
84
|
+
const incoming=new Map(),outgoing=new Map();
|
|
85
|
+
for(const edge of rawEdges){
|
|
86
|
+
if(!edge)continue;
|
|
87
|
+
if(!incoming.has(edge.target))incoming.set(edge.target,[]);
|
|
88
|
+
if(!outgoing.has(edge.source))outgoing.set(edge.source,[]);
|
|
89
|
+
incoming.get(edge.target).push(edge);outgoing.get(edge.source).push(edge);
|
|
90
|
+
}
|
|
91
|
+
const aliasToAgent=new Map();
|
|
92
|
+
const rememberAlias=(alias,id)=>{
|
|
93
|
+
if(alias===undefined||alias===null)return;
|
|
94
|
+
const text=String(alias).trim();
|
|
95
|
+
if(!text)return;
|
|
96
|
+
let bucket=aliasToAgent.get(text);
|
|
97
|
+
if(!bucket){bucket=new Set();aliasToAgent.set(text,bucket)}
|
|
98
|
+
bucket.add(id);
|
|
99
|
+
};
|
|
100
|
+
for(const [id,node] of agents){
|
|
101
|
+
const attrs=attrsOf(node);
|
|
102
|
+
rememberAlias(id,id);
|
|
103
|
+
for(const value of [node.name,attrs.agent_id,attrs.thread_id,attrs.agent_path,attrs.child_agent_path,attrs.nickname]){
|
|
104
|
+
rememberAlias(value,id);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const resolveAgent=value=>{
|
|
108
|
+
if(value===undefined||value===null)return null;
|
|
109
|
+
const text=String(value);
|
|
110
|
+
// Exact canonical id always wins over alias lookup.
|
|
111
|
+
if(agents.has(text))return text;
|
|
112
|
+
const bucket=aliasToAgent.get(text);
|
|
113
|
+
if(!bucket||!bucket.size)return null;
|
|
114
|
+
if(bucket.size===1)return [...bucket][0];
|
|
115
|
+
// Non-unique alias: abstain rather than last-writer-wins.
|
|
116
|
+
return null;
|
|
117
|
+
};
|
|
118
|
+
const uniqueOwner=candidates=>{
|
|
119
|
+
const ids=[...new Set((candidates||[]).filter(Boolean))];
|
|
120
|
+
return ids.length===1?ids[0]:null;
|
|
121
|
+
};
|
|
122
|
+
const ownerForNode=node=>{
|
|
123
|
+
if(!node?.id)return null;
|
|
124
|
+
const direct=[];
|
|
125
|
+
for(const edge of incoming.get(node.id)||[])if(agents.has(edge.source))direct.push(edge.source);
|
|
126
|
+
const directOwner=uniqueOwner(direct);
|
|
127
|
+
if(directOwner)return directOwner;
|
|
128
|
+
if(direct.length)return null; // ambiguous direct owners
|
|
129
|
+
const viaTurn=[];
|
|
130
|
+
for(const edge of incoming.get(node.id)||[]){
|
|
131
|
+
const parent=rawById.get(edge.source);
|
|
132
|
+
if(parent?.type!=='agent_turn')continue;
|
|
133
|
+
for(const grand of incoming.get(parent.id)||[])if(agents.has(grand.source))viaTurn.push(grand.source);
|
|
134
|
+
}
|
|
135
|
+
const turnOwner=uniqueOwner(viaTurn);
|
|
136
|
+
if(turnOwner)return turnOwner;
|
|
137
|
+
if(viaTurn.length)return null;
|
|
138
|
+
const attrs=attrsOf(node);
|
|
139
|
+
const attrOwners=[];
|
|
140
|
+
for(const key of ['owner_agent_id','agent_id','source_agent_id','thread_id','agent_path']){
|
|
141
|
+
const found=resolveAgent(attrs[key]);if(found)attrOwners.push(found);
|
|
142
|
+
}
|
|
143
|
+
return uniqueOwner(attrOwners);
|
|
144
|
+
};
|
|
145
|
+
const agentForAnchor=id=>{
|
|
146
|
+
if(agents.has(id))return id;
|
|
147
|
+
const node=rawById.get(id);
|
|
148
|
+
if(!node)return null;
|
|
149
|
+
return ownerForNode(node);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const modelNameIndex=new Map();
|
|
153
|
+
const rememberModelAlias=(alias,id)=>{
|
|
154
|
+
if(alias===undefined||alias===null)return;
|
|
155
|
+
const text=String(alias).trim().toLowerCase();
|
|
156
|
+
if(!text)return;
|
|
157
|
+
let bucket=modelNameIndex.get(text);
|
|
158
|
+
if(!bucket){bucket=new Set();modelNameIndex.set(text,bucket)}
|
|
159
|
+
bucket.add(id);
|
|
160
|
+
};
|
|
161
|
+
for(const [id,node] of models){
|
|
162
|
+
const attrs=attrsOf(node);
|
|
163
|
+
rememberModelAlias(id,id);
|
|
164
|
+
for(const value of [node.name,attrs.model,attrs.model_name,attrs.native_name]){
|
|
165
|
+
rememberModelAlias(value,id);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const modelHintFor=node=>{
|
|
169
|
+
if(!node)return null;
|
|
170
|
+
const attrs=attrsOf(node);
|
|
171
|
+
for(const key of ['model','model_name','codex_model','default_model','provider_model']){
|
|
172
|
+
const value=attrs[key];
|
|
173
|
+
if(value!==undefined&&value!==null&&String(value).trim())return String(value);
|
|
174
|
+
}
|
|
175
|
+
return null;
|
|
176
|
+
};
|
|
177
|
+
const modelIdFromHint=hint=>{
|
|
178
|
+
if(!hint)return null;
|
|
179
|
+
const lower=String(hint).toLowerCase();
|
|
180
|
+
// Exact canonical id first.
|
|
181
|
+
if(models.has(hint))return hint;
|
|
182
|
+
if(models.has(lower))return lower;
|
|
183
|
+
const bucket=modelNameIndex.get(lower);
|
|
184
|
+
if(!bucket||!bucket.size)return null;
|
|
185
|
+
if(bucket.size===1)return [...bucket][0];
|
|
186
|
+
// Ambiguous model name across resources: abstain (no suffix fuzzy match).
|
|
187
|
+
return null;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const modelEventsByAgent=new Map();
|
|
191
|
+
const addModelEvent=(owner,modelId,item)=>{
|
|
192
|
+
if(!owner||!modelId||!agents.has(owner)||!models.has(modelId))return;
|
|
193
|
+
if(!modelEventsByAgent.has(owner))modelEventsByAgent.set(owner,[]);
|
|
194
|
+
modelEventsByAgent.get(owner).push({modelId,moment:moment(item||{}),edge:item});
|
|
195
|
+
};
|
|
196
|
+
for(const edge of rawEdges){
|
|
197
|
+
if(!agents.has(edge?.source)||!models.has(edge?.target)||!MODEL_RELATIONS.has(relation(edge)))continue;
|
|
198
|
+
addModelEvent(edge.source,edge.target,edge);
|
|
199
|
+
}
|
|
200
|
+
// Hooks and rollout formats often carry the active model on an agent-owned
|
|
201
|
+
// tool/turn/interaction object even when no direct agent -> model edge exists.
|
|
202
|
+
for(const node of rawNodes){
|
|
203
|
+
const owner=ownerForNode(node);
|
|
204
|
+
if(!owner)continue;
|
|
205
|
+
const modelId=modelIdFromHint(modelHintFor(node));
|
|
206
|
+
if(modelId)addModelEvent(owner,modelId,node);
|
|
207
|
+
}
|
|
208
|
+
for(const list of modelEventsByAgent.values())list.sort((a,b)=>{
|
|
209
|
+
// Prefer sequence when both have it; otherwise timestamp; never cross-rank kinds.
|
|
210
|
+
if(a.moment.sequence!==null&&b.moment.sequence!==null){
|
|
211
|
+
return a.moment.sequence-b.moment.sequence;
|
|
212
|
+
}
|
|
213
|
+
if(a.moment.stamp&&b.moment.stamp){
|
|
214
|
+
return String(a.moment.stamp)<String(b.moment.stamp)?-1:String(a.moment.stamp)>String(b.moment.stamp)?1:0;
|
|
215
|
+
}
|
|
216
|
+
if(a.moment.sequence!==null&&b.moment.sequence===null)return -1;
|
|
217
|
+
if(a.moment.sequence===null&&b.moment.sequence!==null)return 1;
|
|
218
|
+
return String(a.moment.id).localeCompare(String(b.moment.id));
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const resolveModel=(owner,item)=>{
|
|
222
|
+
// Item hint is only for the owner/actor side. Callers that resolve a child
|
|
223
|
+
// must pass null as item so an actor tool-call model cannot pollute lookup.
|
|
224
|
+
const hinted=item?modelIdFromHint(modelHintFor(item)):null;
|
|
225
|
+
if(hinted)return hinted;
|
|
226
|
+
const list=modelEventsByAgent.get(owner)||[];
|
|
227
|
+
if(!list.length)return null;
|
|
228
|
+
const at=moment(item||{});
|
|
229
|
+
const eligible=[];
|
|
230
|
+
for(const event of list){
|
|
231
|
+
if(!momentComparable(event.moment,at))continue;
|
|
232
|
+
if(momentLE(event.moment,at))eligible.push(event);
|
|
233
|
+
}
|
|
234
|
+
if(!eligible.length){
|
|
235
|
+
const unique=[...new Set(list.map(event=>event.modelId))];
|
|
236
|
+
return unique.length===1?unique[0]:null;
|
|
237
|
+
}
|
|
238
|
+
// Prefer the latest comparable event; if several tie at the same moment with
|
|
239
|
+
// conflicting models, abstain instead of taking array order.
|
|
240
|
+
let bestMoment=eligible[0].moment;
|
|
241
|
+
for(const event of eligible){
|
|
242
|
+
if(momentLE(bestMoment,event.moment)&&!momentEqual(bestMoment,event.moment))bestMoment=event.moment;
|
|
243
|
+
}
|
|
244
|
+
const tied=eligible.filter(event=>momentEqual(event.moment,bestMoment));
|
|
245
|
+
const unique=[...new Set(tied.map(event=>event.modelId))];
|
|
246
|
+
return unique.length===1?unique[0]:null;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const occurrences=[];
|
|
250
|
+
const pushOccurrence=(kind,owner,targets,item,rawNodeIds=[],rawEdgeIds=[])=>{
|
|
251
|
+
if(!kind||!owner||!agents.has(owner))return;
|
|
252
|
+
occurrences.push({
|
|
253
|
+
kind,owner,targets:new Set((targets||[]).filter(id=>agents.has(id)&&id!==owner)),
|
|
254
|
+
item:item||{},modelId:resolveModel(owner,item||{}),
|
|
255
|
+
rawNodeIds:[...rawNodeIds],rawEdgeIds:[...rawEdgeIds],
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
for(const node of rawNodes){
|
|
260
|
+
if(node?.type!=='agent_interaction'||!node.id)continue;
|
|
261
|
+
const kind=actionName(attrsOf(node).kind||node.name);
|
|
262
|
+
if(!kind)continue;
|
|
263
|
+
const sources=(incoming.get(node.id)||[]).filter(edge=>relation(edge)==='STARTED_AGENT_INTERACTION');
|
|
264
|
+
const targets=(outgoing.get(node.id)||[]).filter(edge=>relation(edge)==='TARGETED_BY_AGENT_INTERACTION');
|
|
265
|
+
const ownerCandidates=sources.map(edge=>agentForAnchor(edge.source));
|
|
266
|
+
const owner=uniqueOwner(ownerCandidates);
|
|
267
|
+
if(!owner)continue;
|
|
268
|
+
// Unknown endpoints keep the occurrence target-less rather than inventing uniqueness.
|
|
269
|
+
const peerIds=[];
|
|
270
|
+
let peersComplete=true;
|
|
271
|
+
for(const edge of targets){
|
|
272
|
+
const peer=agentForAnchor(edge.target);
|
|
273
|
+
if(!peer){peersComplete=false;continue}
|
|
274
|
+
peerIds.push(peer);
|
|
275
|
+
}
|
|
276
|
+
if(targets.length&&!peersComplete&&!peerIds.length)continue;
|
|
277
|
+
pushOccurrence(kind,owner,peerIds,node,[node.id],[...sources,...targets].map(edge=>edge.id).filter(Boolean));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
for(const node of rawNodes){
|
|
281
|
+
if(node?.type!=='agent_message'||!node.id)continue;
|
|
282
|
+
const sent=(incoming.get(node.id)||[]).filter(edge=>relation(edge)==='SENT_AGENT_MESSAGE');
|
|
283
|
+
const delivered=(outgoing.get(node.id)||[]).filter(edge=>relation(edge)==='DELIVERED_AGENT_MESSAGE');
|
|
284
|
+
const owner=uniqueOwner(sent.map(edge=>agentForAnchor(edge.source)));
|
|
285
|
+
if(!owner)continue;
|
|
286
|
+
const peerIds=[];
|
|
287
|
+
let peersComplete=true;
|
|
288
|
+
for(const edge of delivered){
|
|
289
|
+
const peer=agentForAnchor(edge.target);
|
|
290
|
+
if(!peer){peersComplete=false;continue}
|
|
291
|
+
peerIds.push(peer);
|
|
292
|
+
}
|
|
293
|
+
if(delivered.length&&!peersComplete&&!peerIds.length)continue;
|
|
294
|
+
pushOccurrence('send_input',owner,peerIds,node,[node.id],[...sent,...delivered].map(edge=>edge.id).filter(Boolean));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
for(const edge of rawEdges){
|
|
298
|
+
const kind=DIRECT_ACTION_RELATIONS.get(relation(edge));
|
|
299
|
+
if(!kind)continue;
|
|
300
|
+
const owner=agentForAnchor(edge.source),target=agentForAnchor(edge.target);
|
|
301
|
+
if(owner&&target&&owner!==target)pushOccurrence(kind,owner,[target],edge,[],[edge.id].filter(Boolean));
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
for(const call of rawNodes){
|
|
305
|
+
if(!['tool_call','tool_call_observation'].includes(String(call?.type||''))||!call.id)continue;
|
|
306
|
+
let tool=null;
|
|
307
|
+
for(const edge of outgoing.get(call.id)||[]){
|
|
308
|
+
if(relation(edge)!=='USES_TOOL')continue;
|
|
309
|
+
const candidate=rawById.get(edge.target);
|
|
310
|
+
if(candidate?.type==='tool'){tool=candidate;break}
|
|
311
|
+
}
|
|
312
|
+
const kind=actionName(attrsOf(call).tool_name||call.name||attrsOf(tool).native_name||tool?.name);
|
|
313
|
+
if(!kind)continue;
|
|
314
|
+
const owner=ownerForNode(call);
|
|
315
|
+
if(!owner)continue;
|
|
316
|
+
const attrs=attrsOf(call),targets=[];
|
|
317
|
+
for(const key of ['target_agent_id','recipient_agent_id','recipient','agent_id']){
|
|
318
|
+
const found=resolveAgent(attrs[key]);if(found&&found!==owner)targets.push(found);
|
|
319
|
+
}
|
|
320
|
+
for(const key of ['target_agent_ids','recipient_agent_ids','recipients','agent_ids']){
|
|
321
|
+
const values=attrs[key];
|
|
322
|
+
if(Array.isArray(values))for(const value of values){const found=resolveAgent(value);if(found&&found!==owner)targets.push(found)}
|
|
323
|
+
}
|
|
324
|
+
pushOccurrence(kind,owner,targets,call,[call.id],[]);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if(!occurrences.length&&![...modelEventsByAgent.values()].some(list=>list.length))return display;
|
|
328
|
+
|
|
329
|
+
const groups=new Map();
|
|
330
|
+
for(const occurrence of occurrences){
|
|
331
|
+
const key=`${occurrence.owner}\u0000${occurrence.kind}\u0000${occurrence.modelId||''}`;
|
|
332
|
+
let group=groups.get(key);
|
|
333
|
+
if(!group){
|
|
334
|
+
group={owner:occurrence.owner,kind:occurrence.kind,modelId:occurrence.modelId,targets:new Set(),rawNodeIds:new Set(),rawEdgeIds:new Set(),occurrences:[]};
|
|
335
|
+
groups.set(key,group);
|
|
336
|
+
}
|
|
337
|
+
for(const id of occurrence.targets)group.targets.add(id);
|
|
338
|
+
for(const id of occurrence.rawNodeIds)group.rawNodeIds.add(id);
|
|
339
|
+
for(const id of occurrence.rawEdgeIds)group.rawEdgeIds.add(id);
|
|
340
|
+
group.occurrences.push(occurrence);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const roots=[...agents.values()].filter(node=>{
|
|
344
|
+
const attrs=attrsOf(node);
|
|
345
|
+
return attrs.viewer_root===true||attrs.agent_role==='root'||attrs.agent_path==='/root'||attrs.root_agent_path==='/root'||node.name==='/root';
|
|
346
|
+
}).map(node=>node.id);
|
|
347
|
+
const spawnParents=new Map();
|
|
348
|
+
for(const group of groups.values()){
|
|
349
|
+
if(group.kind!=='spawn_agent')continue;
|
|
350
|
+
for(const child of group.targets)if(!spawnParents.has(child))spawnParents.set(child,group.owner);
|
|
351
|
+
}
|
|
352
|
+
if(!roots.length){
|
|
353
|
+
const candidates=[...agents.keys()].filter(id=>!spawnParents.has(id));
|
|
354
|
+
if(candidates.length)roots.push(...candidates.sort());
|
|
355
|
+
}
|
|
356
|
+
const agentRank=new Map(roots.map(id=>[id,0]));
|
|
357
|
+
for(let pass=0;pass<agents.size+2;pass++){
|
|
358
|
+
let changed=false;
|
|
359
|
+
for(const group of groups.values()){
|
|
360
|
+
if(group.kind!=='spawn_agent'||!agentRank.has(group.owner))continue;
|
|
361
|
+
const modelOffset=group.modelId?1:0,actionRank=agentRank.get(group.owner)+modelOffset+1;
|
|
362
|
+
for(const child of group.targets){
|
|
363
|
+
const wanted=actionRank+1,current=agentRank.get(child);
|
|
364
|
+
if(current===undefined||wanted<current){agentRank.set(child,wanted);changed=true}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if(!changed)break;
|
|
368
|
+
}
|
|
369
|
+
for(const id of agents.keys())if(!agentRank.has(id))agentRank.set(id,0);
|
|
370
|
+
|
|
371
|
+
const addedNodes=[],addedEdges=[],contextIds=new Map(),contextifiedModels=new Set();
|
|
372
|
+
const contextId=(owner,modelId)=>`${owner}\u0000${modelId}`;
|
|
373
|
+
const ensureContext=(owner,modelId)=>{
|
|
374
|
+
if(!modelId||!models.has(modelId))return null;
|
|
375
|
+
const key=contextId(owner,modelId);
|
|
376
|
+
if(contextIds.has(key))return contextIds.get(key);
|
|
377
|
+
const model=models.get(modelId),id=`viewer:model-context:${encodeURIComponent(owner)}:${encodeURIComponent(modelId)}`;
|
|
378
|
+
const rank=(agentRank.get(owner)||0)+1;
|
|
379
|
+
const node={
|
|
380
|
+
id,type:'model',name:model.name||attrsOf(model).model||modelId,
|
|
381
|
+
attributes:{...attrsOf(model),viewer_only:true,viewer_model_context:true,owner_agent_id:owner,model_resource_id:modelId,viewer_flow_rank:rank,provider:attrsOf(model).provider||provider(agents.get(owner))}
|
|
382
|
+
};
|
|
383
|
+
addedNodes.push(node);
|
|
384
|
+
addedEdges.push({
|
|
385
|
+
id:`viewer:${owner}--MODEL_CONTEXT-->${id}`,source:owner,target:id,relation:'MODEL_CONTEXT',
|
|
386
|
+
count:1,viewer_only:true,causal:false,inferred:false,
|
|
387
|
+
attributes:{viewer_only:true,projection:'execution_flow',model_resource_id:modelId}
|
|
388
|
+
});
|
|
389
|
+
contextIds.set(key,id);contextifiedModels.add(modelId);return id;
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
for(const [owner,list] of modelEventsByAgent){
|
|
393
|
+
for(const modelId of new Set(list.map(item=>item.modelId)))ensureContext(owner,modelId);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const consumedRawNodes=new Set(),consumedRawEdges=new Set(),consumedCallIds=new Set();
|
|
397
|
+
const contentRefFromNode=(contentNode,edge,direction)=>{
|
|
398
|
+
const attrs=attrsOf(contentNode);
|
|
399
|
+
const viewer=attrs.viewer_content&&typeof attrs.viewer_content==='object'?attrs.viewer_content:{};
|
|
400
|
+
return{
|
|
401
|
+
content_node_id:contentNode.id,
|
|
402
|
+
raw_node_id:contentNode.id,
|
|
403
|
+
raw_edge_id:edge?.id||null,
|
|
404
|
+
relation:edge?.relation||null,
|
|
405
|
+
direction:direction||null,
|
|
406
|
+
sha256:viewer.sha256||attrs.sha256||attrs.content_sha256||null,
|
|
407
|
+
path:viewer.safe_relative_path||attrs.path||attrs.content_path||null,
|
|
408
|
+
size_bytes:viewer.size_bytes??attrs.size_bytes??attrs.content_size_bytes??null,
|
|
409
|
+
media_type:viewer.media_type||attrs.media_type||attrs.content_media_type||null,
|
|
410
|
+
content_kind:viewer.content_kind||attrs.content_kind||contentNode.name||null,
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
for(const group of groups.values()){
|
|
414
|
+
const context=group.modelId?ensureContext(group.owner,group.modelId):null;
|
|
415
|
+
const source=context||group.owner;
|
|
416
|
+
const baseRank=agentRank.get(group.owner)||0;
|
|
417
|
+
const actionRank=baseRank+(context?2:1);
|
|
418
|
+
const id=`viewer:orchestration:${encodeURIComponent(group.owner)}:${encodeURIComponent(group.modelId||'unresolved')}:${group.kind}`;
|
|
419
|
+
const contentRefs=[];
|
|
420
|
+
const toolCallOccurrences=[];
|
|
421
|
+
for(const rawId of group.rawNodeIds){
|
|
422
|
+
const rawNode=rawById.get(rawId);
|
|
423
|
+
if(!rawNode)continue;
|
|
424
|
+
if(String(rawNode.type||'')==='observed_content'){
|
|
425
|
+
contentRefs.push(contentRefFromNode(rawNode,null,'node'));
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
for(const edge of [...(outgoing.get(rawId)||[]),...(incoming.get(rawId)||[])]){
|
|
429
|
+
const peerId=edge.source===rawId?edge.target:edge.source;
|
|
430
|
+
const peer=rawById.get(peerId);
|
|
431
|
+
if(peer?.type!=='observed_content')continue;
|
|
432
|
+
const direction=edge.source===rawId?'outgoing':'incoming';
|
|
433
|
+
const ref=contentRefFromNode(peer,edge,direction);
|
|
434
|
+
if(!contentRefs.some(item=>item.content_node_id===ref.content_node_id&&item.raw_edge_id===ref.raw_edge_id)){
|
|
435
|
+
contentRefs.push(ref);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
if(['tool_call','tool_call_observation'].includes(String(rawNode?.type||''))){
|
|
439
|
+
consumedCallIds.add(rawId);
|
|
440
|
+
const attrs=attrsOf(rawNode);
|
|
441
|
+
let toolId=null;
|
|
442
|
+
for(const edge of outgoing.get(rawId)||[]){
|
|
443
|
+
if(relation(edge)==='USES_TOOL'||relation(edge)==='RESOLVED_TOOL'){toolId=edge.target;break}
|
|
444
|
+
}
|
|
445
|
+
toolCallOccurrences.push({
|
|
446
|
+
invocation_id:rawId,
|
|
447
|
+
owner_id:group.owner,
|
|
448
|
+
tool_id:toolId,
|
|
449
|
+
call_ids:[rawId],
|
|
450
|
+
first_sequence:Number.isInteger(rawNode.first_sequence)?rawNode.first_sequence:null,
|
|
451
|
+
last_sequence:Number.isInteger(rawNode.last_sequence)?rawNode.last_sequence:null,
|
|
452
|
+
first_seen:rawNode.first_seen||null,
|
|
453
|
+
last_seen:rawNode.last_seen||null,
|
|
454
|
+
input:attrs.arguments??attrs.args??attrs.tool_input??attrs.input??attrs.parameters??attrs.request??null,
|
|
455
|
+
output:attrs.output??attrs.result??attrs.tool_output??attrs.response??null,
|
|
456
|
+
content_references:contentRefs.filter(ref=>ref.raw_edge_id&&[...(outgoing.get(rawId)||[]),...(incoming.get(rawId)||[])].some(edge=>edge.id===ref.raw_edge_id)),
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
addedNodes.push({
|
|
461
|
+
id,type:'tool',name:group.kind,
|
|
462
|
+
attributes:{
|
|
463
|
+
viewer_only:true,viewer_orchestration_action:true,orchestration_kind:group.kind,
|
|
464
|
+
owner_agent_id:group.owner,model_context_id:context,model_resource_id:group.modelId,
|
|
465
|
+
viewer_flow_rank:actionRank,provider:provider(agents.get(group.owner)),
|
|
466
|
+
evidence_node_ids:[...group.rawNodeIds].sort(),evidence_edge_ids:[...group.rawEdgeIds].sort(),
|
|
467
|
+
viewer_occurrence_count:group.occurrences.length,
|
|
468
|
+
viewer_model_context_unresolved:!context||undefined,
|
|
469
|
+
viewer_content_references:contentRefs,
|
|
470
|
+
viewer_tool_call_occurrences:toolCallOccurrences,
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
addedEdges.push({
|
|
474
|
+
id:`viewer:${source}--PERFORMED_ORCHESTRATION-->${id}`,source,target:id,
|
|
475
|
+
relation:'PERFORMED_ORCHESTRATION',count:group.occurrences.length,viewer_only:true,causal:false,inferred:false,
|
|
476
|
+
attributes:{viewer_only:true,projection:'execution_flow',orchestration_kind:group.kind,evidence_node_ids:[...group.rawNodeIds],evidence_edge_ids:[...group.rawEdgeIds]}
|
|
477
|
+
});
|
|
478
|
+
const targetRelation=ACTION_RELATION.get(group.kind)||'TARGETED_AGENT';
|
|
479
|
+
for(const target of [...group.targets].sort()){
|
|
480
|
+
addedEdges.push({
|
|
481
|
+
id:`viewer:${id}--${targetRelation}-->${target}`,source:id,target,relation:targetRelation,
|
|
482
|
+
count:1,viewer_only:true,causal:false,inferred:false,
|
|
483
|
+
attributes:{viewer_only:true,projection:'execution_flow',evidence_node_ids:[...group.rawNodeIds],evidence_edge_ids:[...group.rawEdgeIds]}
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
for(const rawId of group.rawNodeIds)consumedRawNodes.add(rawId);
|
|
487
|
+
for(const rawId of group.rawEdgeIds)consumedRawEdges.add(rawId);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// Shared tool definitions / model resources stay unless every remaining USES_TOOL
|
|
491
|
+
// into them came from consumed calls. Consuming one owner's call must not wipe the
|
|
492
|
+
// shared definition for other owners or unresolved calls.
|
|
493
|
+
const hideToolDefs=new Set();
|
|
494
|
+
for(const [toolId,node] of [...rawById].filter(([,n])=>n?.type==='tool')){
|
|
495
|
+
const uses=(incoming.get(toolId)||[]).filter(edge=>['USES_TOOL','RESOLVED_TOOL'].includes(relation(edge)));
|
|
496
|
+
if(!uses.length)continue;
|
|
497
|
+
// Keep shared tool definitions when any live use remains: another owner's
|
|
498
|
+
// unconsumed call, an agent-direct USES_TOOL, or unresolved evidence.
|
|
499
|
+
const allConsumedCalls=uses.every(edge=>{
|
|
500
|
+
const src=rawById.get(edge.source);
|
|
501
|
+
const isCall=['tool_call','tool_call_observation'].includes(String(src?.type||''));
|
|
502
|
+
return isCall&&consumedCallIds.has(edge.source);
|
|
503
|
+
});
|
|
504
|
+
if(allConsumedCalls)hideToolDefs.add(toolId);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
const flowNodes=display.nodes.map(node=>{
|
|
508
|
+
if(node?.type!=='agent'||!agentRank.has(node.id))return node;
|
|
509
|
+
return{...node,attributes:{...attrsOf(node),viewer_flow_rank:agentRank.get(node.id)}};
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
const modelRelation=edge=>MODEL_RELATIONS.has(relation(edge))||relation(edge)==='MODEL_CONTEXT';
|
|
513
|
+
const orchestrationRelation=edge=>DIRECT_ACTION_RELATIONS.has(relation(edge));
|
|
514
|
+
let nodes=flowNodes.filter(node=>!consumedRawNodes.has(node.id)&&!hideToolDefs.has(node.id));
|
|
515
|
+
let edges=display.edges.filter(edge=>{
|
|
516
|
+
if(consumedRawEdges.has(edge.id))return false;
|
|
517
|
+
// Keep unconsumed inferred / provider orchestration evidence. Only hide edges
|
|
518
|
+
// that were actually folded into an occurrence (tracked via consumedRawEdges).
|
|
519
|
+
if(orchestrationRelation(edge)&&agents.has(edge.source)&&agents.has(edge.target)){
|
|
520
|
+
return !consumedRawEdges.has(edge.id);
|
|
521
|
+
}
|
|
522
|
+
if(hideToolDefs.has(edge.source)||hideToolDefs.has(edge.target))return false;
|
|
523
|
+
// Only supersede an owner→model edge when THAT owner already has a viewer
|
|
524
|
+
// model-context for the same model. Other owners' shared-model usage stays.
|
|
525
|
+
if(modelRelation(edge)&&agents.has(edge.source)&&contextIds.has(contextId(edge.source,edge.target)))return false;
|
|
526
|
+
return true;
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
for(const modelId of contextifiedModels){
|
|
530
|
+
const remaining=edges.filter(edge=>edge.source===modelId||edge.target===modelId);
|
|
531
|
+
// Keep the raw model resource whenever any non-superseded usage remains
|
|
532
|
+
// (another owner, unresolved call, or non-agent attachment).
|
|
533
|
+
if(!remaining.length)nodes=nodes.filter(node=>node.id!==modelId);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const known=new Set(nodes.map(node=>node.id));
|
|
537
|
+
for(const node of addedNodes)if(!known.has(node.id)){known.add(node.id);nodes.push(node)}
|
|
538
|
+
const edgeIds=new Set(edges.map(edge=>edge.id));
|
|
539
|
+
for(const edge of addedEdges)if(!edgeIds.has(edge.id)){edgeIds.add(edge.id);edges.push(edge)}
|
|
540
|
+
|
|
541
|
+
return{
|
|
542
|
+
...display,nodes,edges,node_count:nodes.length,edge_count:edges.length,
|
|
543
|
+
dashboard_projection:{
|
|
544
|
+
...(display.dashboard_projection||{}),
|
|
545
|
+
execution_flow_projection:true,
|
|
546
|
+
model_context_node_count:addedNodes.filter(node=>attrsOf(node).viewer_model_context).length,
|
|
547
|
+
orchestration_action_node_count:addedNodes.filter(node=>attrsOf(node).viewer_orchestration_action).length,
|
|
548
|
+
unique_agent_node_count:nodes.filter(node=>node.type==='agent').length,
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
if(typeof execweaveDashboardGraph==='function'){
|
|
554
|
+
const execweaveDashboardGraphBeforeExecutionFlow=execweaveDashboardGraph;
|
|
555
|
+
execweaveDashboardGraph=function(data){
|
|
556
|
+
return execweaveExecutionFlowProjection(execweaveDashboardGraphBeforeExecutionFlow(data),data);
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function execweaveApplyExecutionFlowColumns(topo){
|
|
561
|
+
if(!topo?.spec||typeof nodeById==='undefined')return topo;
|
|
562
|
+
const ranked=[];
|
|
563
|
+
for(const [id,spec] of topo.spec){
|
|
564
|
+
const node=nodeById.get(id),rank=Number(attrsOf(node).viewer_flow_rank);
|
|
565
|
+
if(!node||!Number.isFinite(rank))continue;
|
|
566
|
+
ranked.push({id,spec,rank});
|
|
567
|
+
}
|
|
568
|
+
if(ranked.length<2)return topo;
|
|
569
|
+
const widthByRank=new Map();
|
|
570
|
+
for(const item of ranked)widthByRank.set(item.rank,Math.max(widthByRank.get(item.rank)||160,typeof execweaveWidthOf==='function'?execweaveWidthOf(item.id):160));
|
|
571
|
+
const ranks=[...widthByRank.keys()].sort((a,b)=>a-b);
|
|
572
|
+
const minRank=ranks[0],rootItems=ranked.filter(item=>item.rank===minRank);
|
|
573
|
+
let x=Math.min(...rootItems.map(item=>item.spec.x));
|
|
574
|
+
if(rootItems.some(item=>attrsOf(nodeById.get(item.id)).viewer_session_flow))x=Math.min(...[...topo.spec.values()].map(spec=>spec.x));
|
|
575
|
+
if(!Number.isFinite(x))x=0;
|
|
576
|
+
const xByRank=new Map();
|
|
577
|
+
for(const rank of ranks){
|
|
578
|
+
xByRank.set(rank,x);
|
|
579
|
+
x+=(widthByRank.get(rank)||160)+72;
|
|
580
|
+
}
|
|
581
|
+
for(const item of ranked){
|
|
582
|
+
item.spec.x=xByRank.get(item.rank);
|
|
583
|
+
item.spec.flowRank=item.rank;
|
|
584
|
+
}
|
|
585
|
+
if(typeof execweaveRecomputePorts==='function')execweaveRecomputePorts(topo);
|
|
586
|
+
return topo;
|
|
587
|
+
}
|
|
588
|
+
window.execweaveApplyExecutionFlowColumns=execweaveApplyExecutionFlowColumns;
|
|
589
|
+
|
|
590
|
+
if(typeof execweaveBuildTopology==='function'){
|
|
591
|
+
const execweaveBuildTopologyBeforeExecutionFlow=execweaveBuildTopology;
|
|
592
|
+
execweaveBuildTopology=function(){
|
|
593
|
+
return execweaveApplyExecutionFlowColumns(execweaveBuildTopologyBeforeExecutionFlow());
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
window.__execweaveExecutionFlow={
|
|
598
|
+
version:1,
|
|
599
|
+
project:execweaveExecutionFlowProjection,
|
|
600
|
+
applyColumns:execweaveApplyExecutionFlowColumns,
|
|
601
|
+
};
|
|
602
|
+
})();
|
|
603
|
+
"""
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
def inject_execution_flow(html: str) -> str:
|
|
607
|
+
"""Add provider-neutral model/orchestration/agent presentation without changing evidence."""
|
|
608
|
+
|
|
609
|
+
if html.count(_STARTUP_SEAM) != 1:
|
|
610
|
+
raise RuntimeError("execution-flow startup seam changed")
|
|
611
|
+
return html.replace(_STARTUP_SEAM, EXECUTION_FLOW_SCRIPT + "\n" + _STARTUP_SEAM, 1)
|