diff --git a/package.json b/package.json index e2b6fb3..7341b15 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hermes-canopy", - "version": "0.2.0", + "version": "0.2.1", "private": true, "type": "module", "description": "Ein Baum für Bots, ihren Bot Chat und ihre bestehenden Unterhaltungen auf einem Gateway.", diff --git a/plugin.js b/plugin.js index 6e1df83..97659d8 100644 --- a/plugin.js +++ b/plugin.js @@ -57,9 +57,25 @@ function normalized(r) { lastActive:activity(r.last_active_at) || activity(r.last_active) || activity(r.started_at)} } -function unsupportedList(error) { - return error?.code === -32601 || error?.code === -32602 || - (error?.code === 4001 && error?.data?.reason === 'invalid_params') +// Errors that cross the desktop IPC bridge can lose their JSON-RPC frame (code/data) and keep only the +// message (see hermes-bots/rpc-errors.ts), so the message is the fallback signal when no numeric code survived. +const UNSUPPORTED_MESSAGE = /method not found|unknown method|no such method|-3260[12]\b|invalid[ _-]?params/i +export function unsupportedList(error) { + if (typeof error?.code === 'number') { + return error.code === -32601 || error.code === -32602 || + (error.code === 4001 && error?.data?.reason === 'invalid_params') + } + return UNSUPPORTED_MESSAGE.test(typeof error?.message === 'string' ? error.message : String(error ?? '')) +} + +/** Short technical cause for the UI, so a failure on one client can be diagnosed without devtools. */ +export function errorDetail(error) { + if (error?.name === 'AbortError') return '' + const code = typeof error?.code === 'number' ? ` (${error.code})` : '' + const reason = typeof error?.data?.reason === 'string' ? ` [${error.data.reason}]` : '' + const raw = typeof error?.message === 'string' ? error.message : String(error ?? '') + const msg = raw.replace(/\s+/g,' ').trim() + return (msg.length > 180 ? `${msg.slice(0,177)}…` : msg) + code + reason } async function loadPersisted(api, route, signal) { @@ -244,7 +260,12 @@ function Bot({route, connection, meta, metaRoute, metaReady, online, expanded, t const focused = useValue(host.state.focusedStoredSessionId) const owner = useValue(host.state.focusedSessionOwner) const q = useQuery({queryKey:botKey(route),enabled:expanded && online, - queryFn:({signal})=>loadBot(host,route,signal),staleTime:20000, + queryFn:async ({signal})=>{ + try {return await loadBot(host,route,signal)} catch (error) { + if (error?.name !== 'AbortError') console.warn(`[${ID}] session list failed for ${route.connectionId}/${route.profile}:`,errorDetail(error)) + throw error + } + },staleTime:20000, refetchInterval:expanded && online ? 90000 : false,retry:false}) const botName = meta?.name || route.profile const botChat = meta?.botChat ?? null @@ -278,6 +299,7 @@ function Bot({route, connection, meta, metaRoute, metaReady, online, expanded, t q.isPending && online && message('Unterhaltungen werden geladen …'), q.isError && el('div',null, message('Unterhaltungen konnten für dieses Profil nicht geladen werden.',true), + errorDetail(q.error) && el('p',{style:{...sr,fontSize:'0.78em',wordBreak:'break-word'}},`Ursache: ${errorDetail(q.error)}`), el('button',{type:'button',style:control,disabled:!online,onClick:()=>q.refetch()},'Erneut versuchen')), q.isSuccess && sessions.length === 0 && message('Keine weiteren Unterhaltungen.'), q.data?.liveAtLimit && message('Das Gateway begrenzt seine Liste laufender Sessions. Weitere aktive Unterhaltungen können fehlen.',true), @@ -336,7 +358,7 @@ function Overview({ctx}) { } export default { - id:ID,name:'Hermes Canopy',version:'0.2.0',defaultEnabled:false, + id:ID,name:'Hermes Canopy',version:'0.2.1',defaultEnabled:false, description:'Ein Baum für Bots, ihren Bot Chat und ihre bestehenden Unterhaltungen auf einem Gateway.', register(ctx) { ctx.register({id:'overview',area:'panes',title:'Übersicht',order:900, diff --git a/test/canopy.test.mjs b/test/canopy.test.mjs index 21b1247..c3c388e 100644 --- a/test/canopy.test.mjs +++ b/test/canopy.test.mjs @@ -7,7 +7,7 @@ const hooks = registerHooks({resolve(specifier, context, next) { if (specifier === 'react/jsx-runtime') return {url: 'data:text/javascript,export const jsx=(type,props)=>({type,props}),jsxs=(type,props)=>({type,props})', shortCircuit:true} return next(specifier, context) }}) -const {default: plugin, routesFor, loadBot, openExisting, openBotChat, botChatOf, avatarSource, CanopyError} = await import('../plugin.js') +const {default: plugin, routesFor, loadBot, openExisting, openBotChat, botChatOf, avatarSource, CanopyError, unsupportedList, errorDetail} = await import('../plugin.js') hooks.deregister() const route = {connectionId:'g', profile:'work',targetProfile:'work',mode:'remote'} const state = name => ({get:()=>name}) @@ -170,3 +170,21 @@ test('Bot Chat open refuses a disconnected gateway or a vanished route', async ( await assert.rejects(openBotChat(moved.host,'g',route,route),/Profilroute/) assert.equal(offline.calls.open.length+moved.calls.open.length,0) }) +test('fallback detection survives errors that lost their JSON-RPC code across IPC', async () => { + assert.equal(unsupportedList({code:-32601}),true) + assert.equal(unsupportedList({code:4001,data:{reason:'invalid_params'}}),true) + assert.equal(unsupportedList({code:4001,data:{reason:'permission_denied'}}),false) + assert.equal(unsupportedList({code:4003,message:'invalid_params'}),false) + assert.equal(unsupportedList(Error("Error invoking remote method 'hermes:gateway': Error: invalid_params")),true) + assert.equal(unsupportedList(Error('Method not found: session.list')),true) + assert.equal(unsupportedList(Error('permission_denied')),false) + const empty=async()=>({sessions:[],total:0,limit:500,offset:0,errors:[]}) + const res=await loadBot({requestProfile:async()=>{throw Error('Error: invalid_params')},listPersistedSessions:empty},route) + assert.equal(res.sessions.length,0) +}) +test('error detail names the technical cause compactly', () => { + assert.equal(errorDetail({message:' request timed out\nafter 20s ',code:4001,data:{reason:'invalid_params'}}), + 'request timed out after 20s (4001) [invalid_params]') + assert.equal(errorDetail({name:'AbortError',message:'x'}),'') + assert.equal(errorDetail(Error('x'.repeat(300))).length,178) +})