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,31 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
FOLD_STATE_JS = r"""
|
|
4
|
+
let selectedFoldNode=null;
|
|
5
|
+
// A deterministic namespace hash, not a cryptographic or identity assertion. The
|
|
6
|
+
// store contains booleans only; transcript text is never written to browser storage.
|
|
7
|
+
function foldHash(value){let a=2166136261,b=3339675911;for(const ch of String(value)){const n=ch.codePointAt(0);a=Math.imul(a^n,16777619);b=Math.imul(b^n,2246822519)}return(a>>>0).toString(16)+(b>>>0).toString(16)}
|
|
8
|
+
function foldScope(node){const coreGraph=window.__execweaveCore?.getGraph?.()||{},staticGraph=window.__execweaveStaticGraph||{},identity=String(coreGraph.session_id||staticGraph.session_id||coreGraph.source_path||staticGraph.source_path||'');return identity?`execweave:folds:v1:${foldHash(identity)}:${foldHash(agentKey(node))}`:null}
|
|
9
|
+
function foldStateFor(node){
|
|
10
|
+
const scope=foldScope(node),key=`agent:${foldHash(agentKey(node))}`;
|
|
11
|
+
let state=foldStateByAgent.get(key);
|
|
12
|
+
if(state){if(scope)state.__execweaveScope=scope;return state}
|
|
13
|
+
state=new Map();state.__execweaveScope=scope||null;
|
|
14
|
+
if(scope)try{const data=JSON.parse(localStorage.getItem(scope)||'null');if(data&&data.version===1&&Array.isArray(data.folds))for(const pair of data.folds.slice(-4096)){if(Array.isArray(pair)&&typeof pair[0]==='string'&&typeof pair[1]==='boolean')Map.prototype.set.call(state,pair[0],pair[1])}}catch(_){}
|
|
15
|
+
const get=state.get.bind(state),has=state.has.bind(state),set=state.set.bind(state);
|
|
16
|
+
state.get=raw=>get(foldHash(raw));state.has=raw=>has(foldHash(raw));
|
|
17
|
+
state.set=(raw,value)=>{set(foldHash(raw),Boolean(value));while(state.size>4096)state.delete(state.keys().next().value);const activeScope=state.__execweaveScope;if(activeScope)try{localStorage.setItem(activeScope,JSON.stringify({version:1,folds:[...state]}))}catch(_){}return state};
|
|
18
|
+
foldStateByAgent.set(key,state);return state;
|
|
19
|
+
}
|
|
20
|
+
function bindFold(fold,state,key,defaultOpen=false){
|
|
21
|
+
fold.dataset.foldKey=key;fold.open=state.has(key)?state.get(key):defaultOpen;
|
|
22
|
+
const initial=fold.open;let touched=false;
|
|
23
|
+
fold.addEventListener('click',event=>{if(event.target.closest?.('summary')?.parentElement===fold){touched=true;state.set(key,!fold.open)}});
|
|
24
|
+
fold.__execweaveRemember=()=>{if(fold.isConnected&&(touched||state.has(key)||fold.open!==initial))state.set(key,fold.open)};
|
|
25
|
+
// Detached details can dispatch a queued toggle after a replacement. It must
|
|
26
|
+
// not overwrite the state of the newly rendered copy.
|
|
27
|
+
fold.addEventListener('toggle',fold.__execweaveRemember);return fold;
|
|
28
|
+
}
|
|
29
|
+
function rememberVisibleFoldState(){for(const fold of details.querySelectorAll('details[data-fold-key]'))fold.__execweaveRemember?.()}
|
|
30
|
+
window.addEventListener('pagehide',rememberVisibleFoldState);
|
|
31
|
+
""".strip()
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""Framework-only communication projection. Provider graphs pass through unchanged."""
|
|
2
|
+
|
|
3
|
+
FRAMEWORK_FLOW_SCRIPT = r"""
|
|
4
|
+
function execweaveFrameworkMessages(display,raw){
|
|
5
|
+
const a=n=>n?.attributes||{},r=e=>String(e?.relation||'').toUpperCase();
|
|
6
|
+
const agents=new Map((raw?.nodes||[]).filter(n=>n.type==='agent'&&a(n).conversation_scope==='framework_agent').map(n=>[n.id,n]));
|
|
7
|
+
if(!agents.size)return display;
|
|
8
|
+
const groups=new Map();
|
|
9
|
+
for(const e of raw.edges||[]){
|
|
10
|
+
if(!['MESSAGE_SENT','MESSAGE_RECEIVED'].includes(r(e))||!agents.has(e.source)||!agents.has(e.target)||e.source===e.target||e.inferred===true)continue;
|
|
11
|
+
const key=`${e.source}\0${e.target}`;
|
|
12
|
+
if(!groups.has(key))groups.set(key,{source:e.source,target:e.target,edges:[]});
|
|
13
|
+
groups.get(key).edges.push(e);
|
|
14
|
+
}
|
|
15
|
+
if(!groups.size)return display;
|
|
16
|
+
function listUnconfirmed(graph){
|
|
17
|
+
const rows=graph?.observation_assessment?.message_delivery?.unconfirmed;
|
|
18
|
+
return Array.isArray(rows)?rows:[];
|
|
19
|
+
}
|
|
20
|
+
let nodes=display.nodes.map(n=>({...n,attributes:{...a(n)}}));
|
|
21
|
+
const hidden=new Set(),hiddenNodes=new Set(),added=[];
|
|
22
|
+
// Stream-only messages and callback logs remain in their owner's inspector.
|
|
23
|
+
// They are not delivery events and must not create dangling routing branches.
|
|
24
|
+
const providers=new Set([...agents.values()].map(n=>a(n).provider));
|
|
25
|
+
for(const n of raw.nodes||[]){
|
|
26
|
+
if(n.type!=='message'||!providers.has(a(n).provider))continue;
|
|
27
|
+
const anchors=(raw.edges||[]).filter(e=>(e.target===n.id&&agents.has(e.source)&&r(e)==='MESSAGE_SENT')||(e.source===n.id&&r(e)==='OBSERVED_AT_PROCESS'));
|
|
28
|
+
if(!anchors.length)continue;
|
|
29
|
+
for(const e of anchors){
|
|
30
|
+
const owner=nodes.find(x=>x.id===(e.source===n.id?e.target:e.source));
|
|
31
|
+
if(owner)owner.attributes.viewer_message_evidence=[...(a(owner).viewer_message_evidence||[]),{message_id:n.id,routing_status:'recipient_not_recorded',evidence_edge_id:e.id}];
|
|
32
|
+
}
|
|
33
|
+
hiddenNodes.add(n.id);
|
|
34
|
+
}
|
|
35
|
+
nodes=nodes.filter(n=>!hiddenNodes.has(n.id));
|
|
36
|
+
const missing=listUnconfirmed(raw);
|
|
37
|
+
for(const group of groups.values()){
|
|
38
|
+
const id=`viewer:messages:${encodeURIComponent(group.source)}:${encodeURIComponent(group.target)}`;
|
|
39
|
+
const receiver=agents.get(group.target);
|
|
40
|
+
const evidence=group.edges.map(e=>e.id).filter(Boolean);
|
|
41
|
+
const unconfirmed=missing.filter(row=>row?.sender_id===group.source&&row?.recipient_id===group.target);
|
|
42
|
+
const receiveObserved=group.edges.some(e=>r(e)==='MESSAGE_RECEIVED');
|
|
43
|
+
// An aggregate route cannot certify the delivery of every message. In
|
|
44
|
+
// particular, one received message must not certify another sent-only one.
|
|
45
|
+
const deliveryState=unconfirmed.length?'receive_not_observed':
|
|
46
|
+
receiveObserved?'receive_event_observed':'send_only';
|
|
47
|
+
for(const eid of evidence)hidden.add(eid);
|
|
48
|
+
nodes.push({id,type:'message',name:`Messages → ${receiver.name||group.target}`,attributes:{
|
|
49
|
+
viewer_only:true,viewer_framework_messages:true,provider:a(receiver).provider,
|
|
50
|
+
sender_agent_id:group.source,recipient_agent_id:group.target,
|
|
51
|
+
viewer_message_delivery_state:deliveryState,
|
|
52
|
+
viewer_message_unconfirmed_count:unconfirmed.length,
|
|
53
|
+
viewer_message_observations:group.edges.map(e=>({relation:e.relation,count:e.count||1,first_seen:e.first_seen,last_seen:e.last_seen,evidence_edge_id:e.id})),
|
|
54
|
+
evidence_edge_ids:evidence,
|
|
55
|
+
}});
|
|
56
|
+
const delivery=unconfirmed.length?'ADDRESSED_TO':
|
|
57
|
+
receiveObserved?'DELIVERED_AGENT_MESSAGE':'ADDRESSED_TO';
|
|
58
|
+
for(const [source,target,relation] of [[group.source,id,'MESSAGE_SENT'],[id,group.target,delivery]]){
|
|
59
|
+
added.push({id:`viewer:${source}--${relation}-->${target}`,source,target,relation,count:1,viewer_only:true,causal:false,inferred:false,
|
|
60
|
+
first_sequence:Math.min(...group.edges.map(e=>e.first_sequence).filter(Number.isInteger)),
|
|
61
|
+
first_seen:group.edges.map(e=>e.first_seen).filter(Boolean).sort()[0],
|
|
62
|
+
attributes:{evidence_edge_ids:evidence,routing_basis:'framework_explicit_participants'}});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const edges=display.edges.filter(e=>!hidden.has(e.id)&&!hiddenNodes.has(e.source)&&!hiddenNodes.has(e.target)).concat(added);
|
|
66
|
+
return {...display,nodes,edges,node_count:nodes.length,edge_count:edges.length};
|
|
67
|
+
}
|
|
68
|
+
"""
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""Surface captured framework model output without replacing reported outcomes."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
FRAMEWORK_MODEL_OUTPUT_JS = r"""
|
|
5
|
+
let frameworkModelOutputView=null;
|
|
6
|
+
window.addEventListener('pagehide',()=>{frameworkModelOutputView=null});
|
|
7
|
+
function frameworkModelOutputKey(node){
|
|
8
|
+
const g=rawGraph()||{};
|
|
9
|
+
return JSON.stringify([g.run_id??null,g.session_id??null,g.source_path??null,node?.id??null]);
|
|
10
|
+
}
|
|
11
|
+
function frameworkModelOutputRows(node){
|
|
12
|
+
if(node?.type!=='agent'||attrs(node).conversation_scope!=='framework_agent')return [];
|
|
13
|
+
const kinds=new Set(['metagpt.model_response','autogen.model_response','camel.model_response']);
|
|
14
|
+
const rows=entries.filter(e=>e?.source_id===node.id&&e.source_type==='agent'&&
|
|
15
|
+
e.relation==='HAS_MODEL_CONTENT'&&kinds.has(e.content_kind)&&
|
|
16
|
+
e.model_response_preview?.schema_version==='1'&&e.model_response_preview.source_id===node.id);
|
|
17
|
+
if(!rows.length)return [];
|
|
18
|
+
// No name/path/root fallback or shared-model inference establishes an owner.
|
|
19
|
+
const paths=new Set(rows.map(e=>e.model_response_preview.agent_path));
|
|
20
|
+
if(paths.size!==1||![...paths][0])return [];
|
|
21
|
+
// Keep only fields this reader renders or passes to the existing body reader.
|
|
22
|
+
// The merged conversation projection is independent and must not drive updates.
|
|
23
|
+
const fields=['source_id','source_type','relation','content_kind','path','sha256',
|
|
24
|
+
'size_bytes','media_type','representation','complete_from_source','first_sequence',
|
|
25
|
+
'last_sequence','first_seen','last_seen','model_response_preview'];
|
|
26
|
+
return rows.map(e=>Object.fromEntries(fields.map(k=>[k,e[k]??null])));
|
|
27
|
+
}
|
|
28
|
+
function frameworkModelOutputSnapshot(node,visible=25){
|
|
29
|
+
const signature=JSON.stringify(frameworkModelOutputRows(node));
|
|
30
|
+
return {key:frameworkModelOutputKey(node),signature,rows:JSON.parse(signature),visible};
|
|
31
|
+
}
|
|
32
|
+
function frameworkModelOutputChanged(node){
|
|
33
|
+
if(!node||node.type!=='agent')return;
|
|
34
|
+
const current=details.querySelector('.execweave-framework-model-output');
|
|
35
|
+
if(current&&frameworkModelOutputView?.key===frameworkModelOutputKey(node)){
|
|
36
|
+
current.__execweaveUpdateNotice?.();return;
|
|
37
|
+
}
|
|
38
|
+
if(current){current.remove();frameworkModelOutputView=null}
|
|
39
|
+
const next=frameworkModelOutputSection(node);
|
|
40
|
+
if(next){const history=details.querySelector('.execweave-history-entry');
|
|
41
|
+
if(history)history.after(next);else details.prepend(next)}
|
|
42
|
+
}
|
|
43
|
+
function frameworkModelOutputSection(node){
|
|
44
|
+
if(node?.type!=='agent'||attrs(node).conversation_scope!=='framework_agent')return null;
|
|
45
|
+
const key=frameworkModelOutputKey(node);
|
|
46
|
+
if(!frameworkModelOutputView||frameworkModelOutputView.key!==key)
|
|
47
|
+
frameworkModelOutputView=frameworkModelOutputSnapshot(node);
|
|
48
|
+
const view=frameworkModelOutputView,rows=view.rows;
|
|
49
|
+
if(!rows.length&&!frameworkModelOutputRows(node).length)return null;
|
|
50
|
+
const section=document.createElement('section');section.className='execweave-framework-model-output';
|
|
51
|
+
section.dataset.agentId=String(node.id);
|
|
52
|
+
const title=document.createElement('div');title.className='execweave-agent-label';title.textContent='Captured model output';
|
|
53
|
+
const note=document.createElement('p');note.className='history-provenance';
|
|
54
|
+
note.textContent='Model response previews for this exact agent, not a verified task result or a replacement for the reported response below. Previews may be limited to 6,000 characters per message and 80 messages per record; open the source for captured bytes and integrity checks.';
|
|
55
|
+
const notice=document.createElement('p');notice.className='history-provenance';notice.setAttribute('role','status');
|
|
56
|
+
const refresh=document.createElement('button');refresh.type='button';refresh.textContent='Refresh captured model output';
|
|
57
|
+
function updateNotice(){
|
|
58
|
+
if(view.key!==frameworkModelOutputKey(selectedNode))return;
|
|
59
|
+
const changed=JSON.stringify(frameworkModelOutputRows(node))!==view.signature;
|
|
60
|
+
notice.textContent=changed?'Updated captured model output is available. The displayed preview is an earlier snapshot until you refresh it.':'';
|
|
61
|
+
notice.hidden=!changed;refresh.hidden=!changed;
|
|
62
|
+
}
|
|
63
|
+
refresh.onclick=()=>{
|
|
64
|
+
if(!section.isConnected||view.key!==frameworkModelOutputKey(selectedNode))return;
|
|
65
|
+
// Include default-open folds: a newer latest record must not close the one
|
|
66
|
+
// the reader was already inspecting. Store booleans, not response bodies.
|
|
67
|
+
const state=foldStateFor(node);
|
|
68
|
+
for(const fold of section.querySelectorAll('details[data-fold-key]'))state.set(fold.dataset.foldKey,fold.open);
|
|
69
|
+
frameworkModelOutputView=frameworkModelOutputSnapshot(node,view.visible);
|
|
70
|
+
const next=frameworkModelOutputSection(node);
|
|
71
|
+
if(next)section.replaceWith(next);else section.remove();
|
|
72
|
+
};
|
|
73
|
+
section.__execweaveUpdateNotice=updateNotice;
|
|
74
|
+
section.append(title,note,notice,refresh);updateNotice();
|
|
75
|
+
const ordered=rows.slice().sort((a,b)=>String(b.first_seen||'').localeCompare(String(a.first_seen||''))||
|
|
76
|
+
(Number(b.first_sequence)||0)-(Number(a.first_sequence)||0));
|
|
77
|
+
const state=foldStateFor(node);let shown=0;
|
|
78
|
+
const more=document.createElement('button');more.type='button';more.textContent='Show more model output records';
|
|
79
|
+
const count=document.createElement('p');count.className='history-provenance';
|
|
80
|
+
function appendPage(){
|
|
81
|
+
for(const e of ordered.slice(shown,shown+25)){
|
|
82
|
+
const fold=document.createElement('details');fold.className='execweave-agent-older execweave-framework-model-record';
|
|
83
|
+
const key='model-output:'+JSON.stringify([node.id,e.path,e.first_sequence,e.first_seen]);
|
|
84
|
+
bindFold(fold,state,key,shown===0&&e===ordered[0]);
|
|
85
|
+
const summary=document.createElement('summary');
|
|
86
|
+
summary.textContent=[moment(e.first_seen),e.content_kind,'Captured response record'].filter(Boolean).join(' · ');
|
|
87
|
+
fold.appendChild(summary);
|
|
88
|
+
let populated=false;
|
|
89
|
+
function populate(){
|
|
90
|
+
if(populated)return;populated=true;
|
|
91
|
+
const p=e.model_response_preview;
|
|
92
|
+
const messages=Array.isArray(p.messages)?p.messages:[];
|
|
93
|
+
for(const message of messages.slice(0,80)){
|
|
94
|
+
if(message?.sender!==p.agent_path)continue;
|
|
95
|
+
const body=document.createElement('pre');body.className='execweave-agent-body';
|
|
96
|
+
body.textContent=isEncrypted(message)?ENCRYPTED_NOTICE:typeof message.text==='string'?message.text.slice(0,6000):'Plaintext not available in this preview.';
|
|
97
|
+
fold.appendChild(body);
|
|
98
|
+
}
|
|
99
|
+
if(!messages.length)fold.appendChild(card('Preview','Plaintext not available in this preview. Open the recorded source to check its content.'));
|
|
100
|
+
if(p.messages_truncated||messages.length>80)fold.appendChild(card('Preview limit','Additional messages are not included in this preview.'));
|
|
101
|
+
window.__execweaveContentBrowser?.attach(fold,[e],String(node.id));
|
|
102
|
+
}
|
|
103
|
+
summary.addEventListener('click',()=>{if(!fold.open)populate()});
|
|
104
|
+
if(fold.open)populate();
|
|
105
|
+
fold.addEventListener('toggle',()=>{if(fold.isConnected&&fold.open)populate()});
|
|
106
|
+
section.insertBefore(fold,count);
|
|
107
|
+
}
|
|
108
|
+
shown=Math.min(shown+25,ordered.length);view.visible=Math.max(view.visible,shown);
|
|
109
|
+
count.textContent=`Showing ${shown}/${ordered.length} captured model-response records, not unique invocation counts.`;
|
|
110
|
+
more.hidden=shown===ordered.length;
|
|
111
|
+
}
|
|
112
|
+
section.append(count,more);more.onclick=appendPage;
|
|
113
|
+
const initialLimit=view.visible;do{appendPage()}while(shown<Math.min(initialLimit,ordered.length));
|
|
114
|
+
return section;
|
|
115
|
+
}
|
|
116
|
+
""".strip()
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def inject_framework_model_output(html: str) -> str:
|
|
120
|
+
"""Add the response reader inside the existing agent-panel closure."""
|
|
121
|
+
if "function frameworkModelOutputSection(node){" in html:
|
|
122
|
+
return html
|
|
123
|
+
render = "function render(node){\n if(!node)return false;"
|
|
124
|
+
entry = " details.appendChild(historyBrowser.buttonFor(node));"
|
|
125
|
+
update = "const previousSignature=selectedConversationSignature;entries=candidate;historyBrowser.changed();"
|
|
126
|
+
if html.count(render) != 1 or html.count(entry) != 1 or html.count(update) != 1:
|
|
127
|
+
raise RuntimeError("framework model-output inspector seam changed")
|
|
128
|
+
return html.replace(render, FRAMEWORK_MODEL_OUTPUT_JS + "\n" + render, 1).replace(
|
|
129
|
+
entry,
|
|
130
|
+
entry + "\n const modelOutput=frameworkModelOutputSection(node);"
|
|
131
|
+
"if(modelOutput)details.appendChild(modelOutput);",
|
|
132
|
+
1,
|
|
133
|
+
).replace(update, update + "frameworkModelOutputChanged(selectedNode);", 1)
|
execweave/viewer_gif.py
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"""Export a node-by-node replay using the Dashboard's real rendered SVG geometry."""
|
|
2
|
+
|
|
3
|
+
GIF_SCRIPT = r"""
|
|
4
|
+
const gifSvg=document.getElementById('svg');
|
|
5
|
+
const gifNotice=document.createElement('span');
|
|
6
|
+
gifNotice.id='gif-notice';gifNotice.setAttribute('role','status');
|
|
7
|
+
gifNotice.style.cssText='font-size:11px;color:var(--muted);max-width:230px';
|
|
8
|
+
finishedActions.appendChild(gifNotice);
|
|
9
|
+
const gifScope="Graph viewport only. Exports a node-by-node topology replay using this Dashboard's real node positions, labels, edge paths, folding, theme, and camera.";
|
|
10
|
+
gifButton.title=gifScope;
|
|
11
|
+
gifButton.setAttribute('aria-description',gifScope);
|
|
12
|
+
const GIF_MAX_BYTES=64*1024*1024,GIF_FINAL_HOLD_MS=900;
|
|
13
|
+
let gifExporting=false;
|
|
14
|
+
|
|
15
|
+
const gifProperties=[
|
|
16
|
+
'color','fill','fill-opacity','fill-rule','stroke','stroke-width','stroke-opacity',
|
|
17
|
+
'stroke-dasharray','stroke-dashoffset','stroke-linecap','stroke-linejoin',
|
|
18
|
+
'stroke-miterlimit','paint-order','opacity','display','visibility','filter',
|
|
19
|
+
'font-family','font-size','font-weight','font-style','font-stretch','letter-spacing',
|
|
20
|
+
'word-spacing','text-anchor','dominant-baseline','text-transform','text-rendering',
|
|
21
|
+
'white-space','transform','transform-origin','transform-box','vector-effect',
|
|
22
|
+
'marker-start','marker-mid','marker-end','clip-path','rx','ry'
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
function observeGifPayload(_data){}
|
|
26
|
+
function captureGifFrame(_force=false){return null;}
|
|
27
|
+
|
|
28
|
+
function gifEdgeId(edge){
|
|
29
|
+
return edge?.id||`${edge?.source||''}:${edge?.relation||''}:${edge?.target||''}`;
|
|
30
|
+
}
|
|
31
|
+
function gifStableCompare(a,b){return a<b?-1:a>b?1:0;}
|
|
32
|
+
function gifMoment(item){
|
|
33
|
+
const sequence=Number.isSafeInteger(item?.first_sequence)&&item.first_sequence>=0?item.first_sequence:null;
|
|
34
|
+
const parsed=Date.parse(String(item?.first_seen||item?.timestamp||''));
|
|
35
|
+
return{sequence,time:Number.isFinite(parsed)?parsed:null};
|
|
36
|
+
}
|
|
37
|
+
function gifOrderedEvents(nodes,edges){
|
|
38
|
+
const events=[
|
|
39
|
+
...edges.map(edge=>({kind:'edge',id:gifEdgeId(edge),item:edge,...gifMoment(edge)})),
|
|
40
|
+
...nodes.map(node=>({kind:'node',id:node.id,item:node,...gifMoment(node)})),
|
|
41
|
+
];
|
|
42
|
+
const tie=(a,b)=>(a.kind===b.kind?0:a.kind==='edge'?-1:1)||gifStableCompare(a.id,b.id);
|
|
43
|
+
const byTime=(a,b)=>((a.time??Infinity)-(b.time??Infinity))||tie(a,b);
|
|
44
|
+
const sequenced=events.filter(event=>event.sequence!==null)
|
|
45
|
+
.sort((a,b)=>a.sequence-b.sequence||byTime(a,b));
|
|
46
|
+
// Sequence is authoritative even under clock skew. Insert timestamp-only
|
|
47
|
+
// observations between monotone sequence/time anchors; do not use a pairwise
|
|
48
|
+
// sequence-or-time comparator, which can form cycles and depend on input order.
|
|
49
|
+
const clock=[];let latest=-Infinity;
|
|
50
|
+
for(const event of sequenced){latest=Math.max(latest,event.time??-Infinity);clock.push(latest);}
|
|
51
|
+
const buckets=Array.from({length:sequenced.length+1},()=>[]);
|
|
52
|
+
for(const event of events){
|
|
53
|
+
if(event.sequence!==null)continue;
|
|
54
|
+
let lo=0,hi=clock.length;
|
|
55
|
+
if(event.time===null)lo=hi;
|
|
56
|
+
else while(lo<hi){const mid=(lo+hi)>>1;if(clock[mid]<=event.time)lo=mid+1;else hi=mid;}
|
|
57
|
+
buckets[lo].push(event);
|
|
58
|
+
}
|
|
59
|
+
const ordered=[];
|
|
60
|
+
for(let i=0;i<buckets.length;i++){
|
|
61
|
+
for(const event of buckets[i].sort(byTime))ordered.push(event);
|
|
62
|
+
if(i<sequenced.length)ordered.push(sequenced[i]);
|
|
63
|
+
}
|
|
64
|
+
return ordered;
|
|
65
|
+
}
|
|
66
|
+
function gifTopologySteps(graph){
|
|
67
|
+
const nodes=[...(graph?.nodes||[])].filter(node=>node?.id);
|
|
68
|
+
const nodeIds=new Set(nodes.map(node=>node.id));
|
|
69
|
+
const edges=[...(graph?.edges||[])]
|
|
70
|
+
.filter(edge=>edge&&nodeIds.has(edge.source)&&nodeIds.has(edge.target));
|
|
71
|
+
const seenNodes=new Set(),seenEdges=new Set(),steps=[];
|
|
72
|
+
const pushNode=nodeId=>{
|
|
73
|
+
if(!nodeId||seenNodes.has(nodeId)||!nodeIds.has(nodeId))return;
|
|
74
|
+
seenNodes.add(nodeId);steps.push({nodeId,edgeId:null});
|
|
75
|
+
};
|
|
76
|
+
const pushEdge=edge=>{
|
|
77
|
+
const id=gifEdgeId(edge);
|
|
78
|
+
if(!id||seenEdges.has(id))return;
|
|
79
|
+
if(!seenNodes.has(edge.source))pushNode(edge.source);
|
|
80
|
+
if(!seenNodes.has(edge.target)){
|
|
81
|
+
seenNodes.add(edge.target);seenEdges.add(id);
|
|
82
|
+
steps.push({nodeId:edge.target,edgeId:id});return;
|
|
83
|
+
}
|
|
84
|
+
seenEdges.add(id);steps.push({nodeId:null,edgeId:id});
|
|
85
|
+
};
|
|
86
|
+
const ordered=gifOrderedEvents(nodes,edges);
|
|
87
|
+
// Only explicit root identity establishes initial context; do not guess that
|
|
88
|
+
// an arbitrary disconnected node or the first edge's source is the root.
|
|
89
|
+
const roots=nodes.filter(node=>node.type==='agent'&&
|
|
90
|
+
(node.attributes?.agent_path==='/root'||node.agent_path==='/root'||node.name==='/root'));
|
|
91
|
+
const rootIds=new Set(roots.map(node=>node.id));
|
|
92
|
+
for(const event of ordered)if(event.kind==='node'&&rootIds.has(event.id))pushNode(event.id);
|
|
93
|
+
for(const event of ordered){if(event.kind==='edge')pushEdge(event.item);else pushNode(event.id);}
|
|
94
|
+
return steps;
|
|
95
|
+
}
|
|
96
|
+
function gifStepDelayMs(stepCount){
|
|
97
|
+
if(stepCount<=1)return GIF_FINAL_HOLD_MS;
|
|
98
|
+
return Math.max(90,Math.min(180,Math.round(7000/Math.max(1,stepCount))));
|
|
99
|
+
}
|
|
100
|
+
function gifSnapshot(visibleNodeIds=null,visibleEdgeIds=null){
|
|
101
|
+
const box=gifSvg.getBoundingClientRect();
|
|
102
|
+
const width=Math.round(box.width),height=Math.round(box.height);
|
|
103
|
+
if(!width||!height)return null;
|
|
104
|
+
const clone=gifSvg.cloneNode(true);
|
|
105
|
+
const originals=[gifSvg,...gifSvg.querySelectorAll('*')];
|
|
106
|
+
const copies=[clone,...clone.querySelectorAll('*')];
|
|
107
|
+
const styles=new Map(),remove=[];
|
|
108
|
+
for(let i=0;i<originals.length;i++){
|
|
109
|
+
const original=originals[i],copy=copies[i],classes=original.classList;
|
|
110
|
+
const nodeId=classes?.contains('node')?original.dataset.id:null;
|
|
111
|
+
const edgeElement=classes?.contains('edge')||classes?.contains('edge-hit')||classes?.contains('label');
|
|
112
|
+
const edgeId=edgeElement?original.dataset.edgeId:null;
|
|
113
|
+
if(visibleNodeIds&&nodeId&&!visibleNodeIds.has(nodeId))remove.push(copy);
|
|
114
|
+
if(visibleEdgeIds&&edgeId&&!visibleEdgeIds.has(edgeId))remove.push(copy);
|
|
115
|
+
|
|
116
|
+
const computed=getComputedStyle(original);
|
|
117
|
+
// Routing metadata can contain NUL-delimited keys. Keep only the two identifiers
|
|
118
|
+
// needed to filter replay frames; all other data/ARIA attributes are non-visual.
|
|
119
|
+
for(const attribute of [...copy.attributes]){
|
|
120
|
+
const keepReplayId=attribute.name==='data-id'||attribute.name==='data-edge-id';
|
|
121
|
+
if((attribute.name.startsWith('data-')&&!keepReplayId)||attribute.name.startsWith('aria-')){
|
|
122
|
+
copy.removeAttribute(attribute.name);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
copy.removeAttribute('style');
|
|
126
|
+
for(const property of gifProperties){
|
|
127
|
+
const value=computed.getPropertyValue(property)
|
|
128
|
+
.replace(/url\(["']?[^)"']*#([^)"' ]+)["']?\)/g,'url(#$1)');
|
|
129
|
+
if(value)copy.style.setProperty(property,value);
|
|
130
|
+
}
|
|
131
|
+
// Freeze the rendered appearance. The GIF is a topology replay, not a replay of
|
|
132
|
+
// CSS animations restarting on each decoded SVG.
|
|
133
|
+
copy.style.setProperty('animation','none');copy.style.setProperty('transition','none');
|
|
134
|
+
const css=copy.style.cssText;
|
|
135
|
+
if(!styles.has(css))styles.set(css,`execweave-gif-style-${styles.size}`);
|
|
136
|
+
copy.removeAttribute('style');copy.classList.add(styles.get(css));
|
|
137
|
+
}
|
|
138
|
+
for(const copy of remove)copy.remove();
|
|
139
|
+
|
|
140
|
+
clone.setAttribute('xmlns','http://www.w3.org/2000/svg');
|
|
141
|
+
clone.setAttribute('width',width);clone.setAttribute('height',height);
|
|
142
|
+
clone.setAttribute('viewBox',`0 0 ${width} ${height}`);
|
|
143
|
+
const ns='http://www.w3.org/2000/svg';
|
|
144
|
+
const stylesheet=document.createElementNS(ns,'style');
|
|
145
|
+
stylesheet.textContent=[...styles].map(([css,name])=>`.${name}{${css}}`).join('\n');
|
|
146
|
+
clone.insertBefore(stylesheet,clone.firstChild);
|
|
147
|
+
const background=document.createElementNS(ns,'rect');
|
|
148
|
+
background.setAttribute('width',width);background.setAttribute('height',height);
|
|
149
|
+
background.setAttribute('fill',getComputedStyle(document.getElementById('graph-panel')).backgroundColor);
|
|
150
|
+
clone.insertBefore(background,clone.firstChild);
|
|
151
|
+
const defs=document.createElementNS(ns,'defs'),pattern=document.createElementNS(ns,'pattern');
|
|
152
|
+
pattern.id='execweave-gif-paper';pattern.setAttribute('width','22');pattern.setAttribute('height','22');pattern.setAttribute('patternUnits','userSpaceOnUse');
|
|
153
|
+
const dot=document.createElementNS(ns,'circle');dot.setAttribute('cx','1');dot.setAttribute('cy','1');dot.setAttribute('r','1');
|
|
154
|
+
dot.setAttribute('fill',`color-mix(in srgb,${getComputedStyle(gifSvg).getPropertyValue('--border')} 52%,transparent)`);
|
|
155
|
+
pattern.appendChild(dot);defs.appendChild(pattern);clone.insertBefore(defs,background);
|
|
156
|
+
const paper=background.cloneNode();paper.setAttribute('fill','url(#execweave-gif-paper)');background.after(paper);
|
|
157
|
+
return{svg:new XMLSerializer().serializeToString(clone),width,height,element:clone};
|
|
158
|
+
}
|
|
159
|
+
function gifReplaySnapshot(base,visibleNodeIds,visibleEdgeIds){
|
|
160
|
+
// Freeze geometry, camera, filtering, labels and theme once per export. A UI
|
|
161
|
+
// update during asynchronous rasterization must never rewrite later frames.
|
|
162
|
+
const clone=base.element.cloneNode(true);
|
|
163
|
+
for(const node of clone.querySelectorAll('.node[data-id]')){
|
|
164
|
+
if(!visibleNodeIds.has(node.getAttribute('data-id')))node.remove();
|
|
165
|
+
}
|
|
166
|
+
for(const edge of clone.querySelectorAll('.edge[data-edge-id],.edge-hit[data-edge-id],.label[data-edge-id]')){
|
|
167
|
+
if(!visibleEdgeIds.has(edge.getAttribute('data-edge-id')))edge.remove();
|
|
168
|
+
}
|
|
169
|
+
return{svg:new XMLSerializer().serializeToString(clone),width:base.width,height:base.height};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function pushWord(out,value){out.push(value&255,(value>>8)&255);}
|
|
173
|
+
function pushText(out,text){for(let i=0;i<text.length;i++)out.push(text.charCodeAt(i)&255);}
|
|
174
|
+
function gifBlocks(data){
|
|
175
|
+
const out=new Uint8Array(data.length+Math.ceil(data.length/255)+1);
|
|
176
|
+
let source=0,target=0;
|
|
177
|
+
while(source<data.length){const size=Math.min(255,data.length-source);out[target++]=size;out.set(data.subarray(source,source+size),target);source+=size;target+=size;}
|
|
178
|
+
return out;
|
|
179
|
+
}
|
|
180
|
+
function lzw(indices){
|
|
181
|
+
const clear=256,end=257,out=[],dictionary=new Map();
|
|
182
|
+
let next=258,size=9,buffer=0,bits=0;
|
|
183
|
+
const emit=code=>{buffer|=code<<bits;bits+=size;while(bits>=8){out.push(buffer&255);buffer>>>=8;bits-=8;}};
|
|
184
|
+
emit(clear);
|
|
185
|
+
if(indices.length){
|
|
186
|
+
let prefix=indices[0];
|
|
187
|
+
for(let i=1;i<indices.length;i++){
|
|
188
|
+
const symbol=indices[i],key=prefix*256+symbol,hit=dictionary.get(key);
|
|
189
|
+
if(hit!==undefined){prefix=hit;continue;}
|
|
190
|
+
emit(prefix);
|
|
191
|
+
if(next<4096){
|
|
192
|
+
dictionary.set(key,next++);
|
|
193
|
+
if(next>(1<<size)&&size<12)size++;
|
|
194
|
+
}else{emit(clear);dictionary.clear();next=258;size=9;}
|
|
195
|
+
prefix=symbol;
|
|
196
|
+
}
|
|
197
|
+
emit(prefix);
|
|
198
|
+
if(next===(1<<size)&&size<12)size++;
|
|
199
|
+
}
|
|
200
|
+
emit(end);if(bits)out.push(buffer&255);return Uint8Array.from(out);
|
|
201
|
+
}
|
|
202
|
+
function gifPixels(imageData){
|
|
203
|
+
const data=imageData.data,counts=new Uint32Array(32768),rs=new Float64Array(32768),gs=new Float64Array(32768),bs=new Float64Array(32768);
|
|
204
|
+
for(let i=0;i<data.length;i+=4){const key=(data[i]>>3)*1024+(data[i+1]>>3)*32+(data[i+2]>>3);counts[key]++;rs[key]+=data[i];gs[key]+=data[i+1];bs[key]+=data[i+2];}
|
|
205
|
+
const colors=[];for(let key=0;key<counts.length;key++)if(counts[key])colors.push(key);
|
|
206
|
+
colors.sort((a,b)=>counts[b]-counts[a]||a-b);
|
|
207
|
+
const palette=new Uint8Array(768),lookup=new Int16Array(32768);lookup.fill(-1);
|
|
208
|
+
const chosen=colors.slice(0,256);
|
|
209
|
+
for(let i=0;i<chosen.length;i++){const k=chosen[i];palette[i*3]=Math.round(rs[k]/counts[k]);palette[i*3+1]=Math.round(gs[k]/counts[k]);palette[i*3+2]=Math.round(bs[k]/counts[k]);lookup[k]=i;}
|
|
210
|
+
for(const k of colors){
|
|
211
|
+
if(lookup[k]>=0)continue;
|
|
212
|
+
const r=rs[k]/counts[k],g=gs[k]/counts[k],b=bs[k]/counts[k];let best=Infinity,index=0;
|
|
213
|
+
for(let j=0;j<chosen.length;j++){const distance=(r-palette[j*3])**2+(g-palette[j*3+1])**2+(b-palette[j*3+2])**2;if(distance<best){best=distance;index=j;}}
|
|
214
|
+
lookup[k]=index;
|
|
215
|
+
}
|
|
216
|
+
const pixels=new Uint8Array(imageData.width*imageData.height);
|
|
217
|
+
for(let i=0,j=0;i<data.length;i+=4,j++)pixels[j]=lookup[(data[i]>>3)*1024+(data[i+1]>>3)*32+(data[i+2]>>3)];
|
|
218
|
+
return{palette,pixels};
|
|
219
|
+
}
|
|
220
|
+
async function rasterGifFrame(frame,width,height){
|
|
221
|
+
const url=URL.createObjectURL(new Blob([frame.svg],{type:'image/svg+xml;charset=utf-8'}));
|
|
222
|
+
try{
|
|
223
|
+
const image=new Image();image.src=url;await image.decode();
|
|
224
|
+
const canvas=document.createElement('canvas');canvas.width=width;canvas.height=height;
|
|
225
|
+
const ctx=canvas.getContext('2d',{willReadFrequently:true});
|
|
226
|
+
ctx.fillStyle='#0a0f16';ctx.fillRect(0,0,width,height);
|
|
227
|
+
ctx.drawImage(image,0,0,frame.width,frame.height);
|
|
228
|
+
return gifPixels(ctx.getImageData(0,0,width,height));
|
|
229
|
+
}finally{URL.revokeObjectURL(url);}
|
|
230
|
+
}
|
|
231
|
+
function gifFrameParts(raster,width,height,delayMs){
|
|
232
|
+
let delay=Math.max(2,Math.round(delayMs/10));
|
|
233
|
+
const parts=[];
|
|
234
|
+
do{
|
|
235
|
+
const chunk=Math.min(65535,delay),block=[0x21,0xF9,4,4];pushWord(block,chunk);block.push(0,0,0x2C);
|
|
236
|
+
pushWord(block,0);pushWord(block,0);pushWord(block,width);pushWord(block,height);block.push(0x87);
|
|
237
|
+
parts.push(Uint8Array.from(block),raster.palette,Uint8Array.of(8),gifBlocks(lzw(raster.pixels)));delay-=chunk;
|
|
238
|
+
}while(delay>0);
|
|
239
|
+
return parts;
|
|
240
|
+
}
|
|
241
|
+
async function downloadGif(){
|
|
242
|
+
if(gifButton.disabled||gifExporting)return;
|
|
243
|
+
if(replaying){gifNotice.textContent='Wait for replay to finish before exporting.';return;}
|
|
244
|
+
const protective=document.getElementById('protective');
|
|
245
|
+
if(protective&&!protective.hidden){gifNotice.textContent='GIF unavailable: graph rendering is paused.';return;}
|
|
246
|
+
const original=gifButton.textContent,replayWasDisabled=replayButton.disabled;
|
|
247
|
+
gifExporting=true;gifButton.disabled=true;replayButton.disabled=true;
|
|
248
|
+
try{
|
|
249
|
+
const graph=core.getDisplayGraph?.()||core.getGraph?.()||{};
|
|
250
|
+
const session=graph.session_id||core.getGraph?.()?.session_id||'run';
|
|
251
|
+
const steps=gifTopologySteps(graph);
|
|
252
|
+
if(!steps.length||!gifSvg.querySelector('.node')){gifNotice.textContent='No visible graph to replay.';return;}
|
|
253
|
+
const base=gifSnapshot();if(!base){gifNotice.textContent='GIF unavailable: graph viewport has no size.';return;}
|
|
254
|
+
if(base.width>65535||base.height>65535){gifNotice.textContent='GIF unavailable: viewport is too large.';return;}
|
|
255
|
+
const visibleNodes=new Set(),visibleEdges=new Set(),stepDelay=gifStepDelayMs(steps.length);
|
|
256
|
+
const header=[];pushText(header,'GIF89a');pushWord(header,base.width);pushWord(header,base.height);header.push(0x70,0,0);
|
|
257
|
+
header.push(0x21,0xFF,0x0B);pushText(header,'NETSCAPE2.0');header.push(3,1,0,0,0);
|
|
258
|
+
const parts=[Uint8Array.from(header)];let encodedBytes=header.length;
|
|
259
|
+
for(let i=0;i<steps.length;i++){
|
|
260
|
+
const step=steps[i];
|
|
261
|
+
if(step.nodeId)visibleNodes.add(step.nodeId);
|
|
262
|
+
if(step.edgeId)visibleEdges.add(step.edgeId);
|
|
263
|
+
gifButton.textContent=`Encoding ${i+1}/${steps.length}`;await sleep(0);
|
|
264
|
+
const frame=gifReplaySnapshot(base,visibleNodes,visibleEdges);
|
|
265
|
+
const raster=await rasterGifFrame(frame,base.width,base.height);
|
|
266
|
+
const frameParts=gifFrameParts(raster,base.width,base.height,i===steps.length-1?GIF_FINAL_HOLD_MS:stepDelay);
|
|
267
|
+
for(const part of frameParts){encodedBytes+=part.byteLength;if(encodedBytes>GIF_MAX_BYTES)throw new Error('topology replay exceeded 64 MB');parts.push(part);}
|
|
268
|
+
}
|
|
269
|
+
parts.push(Uint8Array.of(0x3B));
|
|
270
|
+
const blob=new Blob(parts,{type:'image/gif'}),url=URL.createObjectURL(blob),a=document.createElement('a');
|
|
271
|
+
a.href=url;a.download=`execweave-${session}.gif`;document.body.appendChild(a);a.click();a.remove();
|
|
272
|
+
setTimeout(()=>URL.revokeObjectURL(url),1000);
|
|
273
|
+
gifNotice.textContent=`Saved node-by-node replay (${steps.length} topology steps).`;
|
|
274
|
+
}catch(error){gifNotice.textContent=`GIF export failed: ${error.message}`;}
|
|
275
|
+
finally{gifExporting=false;gifButton.disabled=false;replayButton.disabled=replayWasDisabled;gifButton.textContent=original;}
|
|
276
|
+
}
|
|
277
|
+
if(typeof window!=='undefined')window.__execweaveGifTopologySteps=gifTopologySteps;
|
|
278
|
+
"""
|