mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-30 13:13:25 +00:00
* fix(subscriptions): preserve older-host workflows and explicit timeline recovery Keep established app and SDK workflows available on older daemons without emulating independent directory filters. Restore live timeline membership without choosing the consumer's history recovery policy. Preserve daemon filesystem paths separately from legacy workspace IDs. * fix(client): keep legacy workspace replies scoped to the requested page
71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
import { createPaseoClient, type PaseoClient } from "@getpaseo/client";
|
|
|
|
export function createClient(url: string): PaseoClient {
|
|
return createPaseoClient({
|
|
url,
|
|
});
|
|
}
|
|
|
|
export async function subscribeToEvents(
|
|
url: string,
|
|
agentId: string,
|
|
workspaceId: string,
|
|
): Promise<() => Promise<void>> {
|
|
const client = createClient(url);
|
|
await client.connect();
|
|
|
|
const agents = await client.agents.list({ subscribe: {} });
|
|
const workspaces = await client.workspaces.list({ subscribe: {} });
|
|
|
|
const unsubscribeAgentUpdates = client.agents.subscribe((update) => {
|
|
if (update.kind === "upsert" && update.agent.id === agentId) {
|
|
void update.agent.status;
|
|
}
|
|
});
|
|
|
|
const unsubscribeWorkspaceUpdates = client.workspaces.subscribe((update) => {
|
|
if (update.kind === "upsert" && update.workspace.id === workspaceId) {
|
|
void update.workspace.workspaceDirectory;
|
|
}
|
|
});
|
|
|
|
const unsubscribeTimeline = client.agents.ref(agentId).timeline.subscribe((event) => {
|
|
if (event.event.type === "subscription_restored") {
|
|
console.log("Live subscription restored; request any missed history explicitly.");
|
|
} else if (event.event.type === "error") {
|
|
console.error(event.event.error);
|
|
}
|
|
});
|
|
|
|
await unsubscribeTimeline.ready;
|
|
|
|
return async () => {
|
|
unsubscribeTimeline();
|
|
unsubscribeWorkspaceUpdates();
|
|
unsubscribeAgentUpdates();
|
|
try {
|
|
await Promise.all([agents.subscription.release(), workspaces.subscription.release()]);
|
|
} finally {
|
|
await client.close();
|
|
}
|
|
};
|
|
}
|
|
|
|
export async function refetchTimeline(url: string, agentId: string): Promise<number> {
|
|
const client = createClient(url);
|
|
|
|
try {
|
|
await client.connect();
|
|
|
|
const timeline = await client.agents.ref(agentId).timeline.refetch({
|
|
direction: "before",
|
|
limit: 50,
|
|
projection: "projected",
|
|
});
|
|
|
|
return timeline.entries.length;
|
|
} finally {
|
|
await client.close();
|
|
}
|
|
}
|