mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-06 08:24:46 +00:00
fix(subscriptions): isolate observers and silence unrequested feeds
Filtered plugin observations shared a replaceable directory subscription with the app. Give each observation independent source ownership and route all application feeds through explicit demand, preserving combined listing and subscription.
This commit is contained in:
@@ -13,6 +13,7 @@ import { incrementRpc } from "../shared/increment";
|
||||
export function contributeClient(client: PluginClientContext) {
|
||||
const pills = new Map<string, PluginButtonRegistration>();
|
||||
let stopped = false;
|
||||
const lifetime = new AbortController();
|
||||
const register = (agent: { id: string; workspaceId?: string | null }) => {
|
||||
if (stopped || !agent.workspaceId) return;
|
||||
pills.get(agent.id)?.remove();
|
||||
@@ -39,20 +40,30 @@ export function contributeClient(client: PluginClientContext) {
|
||||
pills.get(agentId)?.remove();
|
||||
pills.delete(agentId);
|
||||
};
|
||||
const unsubscribe = client.paseo.agents.subscribe((update) => {
|
||||
if (update.kind === "remove") remove(update.agentId);
|
||||
else register(update.agent);
|
||||
});
|
||||
void client.paseo.agents
|
||||
.list()
|
||||
.then(({ entries }) => {
|
||||
for (const { agent } of entries) register(agent);
|
||||
.list({ subscribe: {}, signal: lifetime.signal })
|
||||
.then(({ subscription }) => {
|
||||
subscription.subscribe({
|
||||
snapshot: ({ entries }) => {
|
||||
for (const pill of pills.values()) pill.remove();
|
||||
pills.clear();
|
||||
for (const { agent } of entries) register(agent);
|
||||
},
|
||||
update: (message) => {
|
||||
if (message.type !== "agent_update") return;
|
||||
const update = message.payload;
|
||||
if (update.kind === "remove") remove(update.agentId);
|
||||
else register(update.agent);
|
||||
},
|
||||
});
|
||||
return undefined;
|
||||
})
|
||||
.catch(() => undefined);
|
||||
.catch((error) => {
|
||||
if (!stopped) console.error("Agent observation failed", error);
|
||||
});
|
||||
return () => {
|
||||
stopped = true;
|
||||
unsubscribe();
|
||||
lifetime.abort();
|
||||
for (const pill of pills.values()) pill.remove();
|
||||
pills.clear();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user