@andespindola/brainlink 0.1.0-beta.53 → 0.1.0-beta.54
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.
|
@@ -101,6 +101,39 @@ const initialAgentFromUrl = (() => {
|
|
|
101
101
|
}
|
|
102
102
|
})()
|
|
103
103
|
|
|
104
|
+
const selectedAgentStorageKey = 'brainlink:selected-agent'
|
|
105
|
+
|
|
106
|
+
const readStoredAgent = () => {
|
|
107
|
+
try {
|
|
108
|
+
const value = window.localStorage.getItem(selectedAgentStorageKey)?.trim() ?? ''
|
|
109
|
+
return value.length > 0 ? value : ''
|
|
110
|
+
} catch {
|
|
111
|
+
return ''
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const writeStoredAgent = (agentId) => {
|
|
116
|
+
try {
|
|
117
|
+
if (!agentId) {
|
|
118
|
+
window.localStorage.removeItem(selectedAgentStorageKey)
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
window.localStorage.setItem(selectedAgentStorageKey, agentId)
|
|
122
|
+
} catch {}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const syncAgentInUrl = (agentId) => {
|
|
126
|
+
try {
|
|
127
|
+
const url = new URL(window.location.href)
|
|
128
|
+
if (agentId && agentId.trim().length > 0) {
|
|
129
|
+
url.searchParams.set('agent', agentId)
|
|
130
|
+
} else {
|
|
131
|
+
url.searchParams.delete('agent')
|
|
132
|
+
}
|
|
133
|
+
window.history.replaceState({}, '', url.toString())
|
|
134
|
+
} catch {}
|
|
135
|
+
}
|
|
136
|
+
|
|
104
137
|
const agentQuery = (separator = '?') => state.agentId ? separator + 'agent=' + encodeURIComponent(state.agentId) : ''
|
|
105
138
|
|
|
106
139
|
const setGraphStatus = text => {
|
|
@@ -1545,6 +1578,8 @@ const bindEvents = () => {
|
|
|
1545
1578
|
})
|
|
1546
1579
|
elements.agent.addEventListener('change', event => {
|
|
1547
1580
|
state.agentId = event.target.value
|
|
1581
|
+
writeStoredAgent(state.agentId)
|
|
1582
|
+
syncAgentInUrl(state.agentId)
|
|
1548
1583
|
state.selected = null
|
|
1549
1584
|
state.nodeDetails = new Map()
|
|
1550
1585
|
resetContentFilter()
|
|
@@ -1671,7 +1706,7 @@ const loadAgents = async () => {
|
|
|
1671
1706
|
const response = await fetch('/api/agents')
|
|
1672
1707
|
const payload = await response.json()
|
|
1673
1708
|
const agents = Array.isArray(payload.agents) ? payload.agents : []
|
|
1674
|
-
const preferredAgent = state.agentId || initialAgentFromUrl
|
|
1709
|
+
const preferredAgent = state.agentId || initialAgentFromUrl || readStoredAgent()
|
|
1675
1710
|
const currentExists = agents.some(agent => agent.id === preferredAgent)
|
|
1676
1711
|
const selected = currentExists
|
|
1677
1712
|
? preferredAgent
|
|
@@ -1679,6 +1714,8 @@ const loadAgents = async () => {
|
|
|
1679
1714
|
const signature = JSON.stringify(agents.map(agent => [agent.id, agent.documentCount]))
|
|
1680
1715
|
|
|
1681
1716
|
state.agentId = selected
|
|
1717
|
+
writeStoredAgent(selected)
|
|
1718
|
+
syncAgentInUrl(selected)
|
|
1682
1719
|
if (signature !== state.agentsSignature) {
|
|
1683
1720
|
const formatAgentLabel = (agent) => agent.id
|
|
1684
1721
|
elements.agent.innerHTML = agents.length
|
package/package.json
CHANGED