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:
Mohamed Boudra
2026-09-09 22:43:18 +02:00
parent ec4e81ce0f
commit 9b09ba7d48
198 changed files with 9341 additions and 4491 deletions
+20 -9
View File
@@ -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();
};