Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/command-replies.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export function createReplyClient({endpoint='http://127.0.0.1:8790/agents',fetch
}
function fail(taskId,notice){const result={phase:'error',notice};states.set(taskId,result);return {...result};}
function capability(agent,stale=false){return conversationCapability(agent,feed.href,{now:now(),stale:Boolean(stale||agent?.isStale||agent?.freshness?.isStale)});}
function exactRoute(agent,cap){try{const route=new URL(cap.url);return route.origin===feed.origin&&route.pathname===`/agents/${encodeURIComponent(agent.id)}/messages`&&!route.search&&!route.hash;}catch{return false;}}
async function send(agent,message){
const taskId=agent?.taskId;
if(!taskId)return {phase:'error',notice:'The source has not identified a supported task.'};
Expand All @@ -42,7 +41,7 @@ export function createReplyClient({endpoint='http://127.0.0.1:8790/agents',fetch
const value=typeof message==='string'?message.trim():'';
if(!value||value.length>MAX_MESSAGE_LENGTH)return fail(taskId,`Write a message of 1–${MAX_MESSAGE_LENGTH} characters.`);
const shownCapability=capability(agent);
if(!shownCapability.available||!exactRoute(agent,shownCapability))return fail(taskId,shownCapability.reason||'The task has no supported local message route.');
if(!shownCapability.available)return fail(taskId,shownCapability.reason||'The task has no supported local message route.');
active.add(taskId);states.set(taskId,{phase:'checking',notice:'Checking the current task and question…'});
let reserved=false,requestId;
try{
Expand All @@ -56,7 +55,7 @@ export function createReplyClient({endpoint='http://127.0.0.1:8790/agents',fetch
if((currentInput?.id??null)!==(shownInput?.id??null)||inputRequestVersion(currentInput)!==version)return fail(taskId,'The question or its choices changed. Refresh before replying.');
const supported=capability(latest,snapshot.stale);
if(!supported.available)return fail(taskId,supported.reason);
if(!exactRoute(latest,supported)||supported.mode!==shownCapability.mode||supported.url!==shownCapability.url)return fail(taskId,'The supported message route changed. Refresh before sending.');
if(supported.mode!==shownCapability.mode||supported.url!==shownCapability.url)return fail(taskId,'The supported message route changed. Refresh before sending.');
if(supported.mode==='respond'&&!currentInput)return fail(taskId,'The source has not supplied an exact current question.');
if(supported.mode==='redirect'&&currentInput)return fail(taskId,'The task has a pending question. Refresh before replying.');
// Check persistent state again after the read preflight, before reserving the write.
Expand Down
16 changes: 9 additions & 7 deletions src/map-display.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {fullscreenButtonCopy} from './fullscreen.mjs';
import {nextZoom, zoomKey, ZOOM_LEVELS} from './viewport.mjs';

/** Fullscreen and panel chrome live outside the inspector's streaming content. */
export function createMapDisplay({camera, canvas, getMode, onOverview}) {
export function createMapDisplay({camera, canvas, getMode, onOverview, getWorkspaceView=()=> 'town', focusWorkspace}) {
const $ = id => document.getElementById(id);
const root = $('map-shell'), viewport = $('map-viewport'), details = $('details-shell');
const panel = $('panel');
Expand All @@ -13,15 +13,15 @@ export function createMapDisplay({camera, canvas, getMode, onOverview}) {
let frame = 0;
let fullscreenReading = null;
const isActive = () => active;
const focusMap = () => $(getMode() === 'room' ? 'room-canvas' : 'town').focus({preventScroll: true});
const focusMap = () => getWorkspaceView()!=='town' ? focusWorkspace?.() : $(getMode() === 'room' ? 'room-canvas' : 'town').focus({preventScroll: true});

function positionPanel() {
frame = 0;
if (active) {
const r = root.getBoundingClientRect(), v = viewport.getBoundingClientRect();
root.style.setProperty('--details-top', Math.max(12, v.top - r.top + 12) + 'px');
root.style.setProperty('--details-right', Math.max(12, r.right - v.right + 12) + 'px');
root.style.setProperty('--details-bottom', Math.max(12, r.bottom - v.bottom + 12) + 'px');
root.style.setProperty('--details-right', (getWorkspaceView()==='town'?Math.max(12, r.right - v.right + 12):12) + 'px');
root.style.setProperty('--details-bottom', (getWorkspaceView()==='town'?Math.max(12, r.bottom - v.bottom + 12):12) + 'px');
}
camera.resize();
}
Expand All @@ -30,8 +30,10 @@ export function createMapDisplay({camera, canvas, getMode, onOverview}) {
observer.observe(viewport); observer.observe(details);

function syncDetails() {
details.hidden = active && !detailsOpen;
toggle.hidden = !active;
camera.capture();
details.hidden = !detailsOpen;
root.classList.toggle('details-closed',!detailsOpen);
toggle.hidden = false;
toggle.setAttribute('aria-expanded', String(detailsOpen));
toggle.setAttribute('aria-pressed', String(detailsOpen));
positionPanel();
Expand Down Expand Up @@ -67,7 +69,7 @@ export function createMapDisplay({camera, canvas, getMode, onOverview}) {
function syncZoom() {
const zoom = camera.state.zoom;
zoomControls.hidden = getMode() === 'room';
minus.disabled = zoom === ZOOM_LEVELS[0]; plus.disabled = zoom === ZOOM_LEVELS.at(-1);
minus.disabled = zoom <= ZOOM_LEVELS[0]; plus.disabled = zoom === ZOOM_LEVELS.at(-1);
reset.textContent = zoom + '%'; reset.setAttribute('aria-label', 'Map zoom ' + zoom + '%. Reset to 100%');
}
function changeZoom(action) {
Expand Down
Loading
Loading