paseo-recap 0.2.2 → 0.2.3
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.
- package/client/pills.tsx +105 -102
- package/index.client.tsx +2 -2
- package/package.json +1 -1
package/client/pills.tsx
CHANGED
|
@@ -29,133 +29,136 @@ function pillButton({
|
|
|
29
29
|
return { visible, label, icon: busy ? SpinnerIcon : icon };
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
export interface RecapPills {
|
|
33
|
+
start(): void;
|
|
34
|
+
stop(): void;
|
|
35
|
+
refresh(): Promise<void>;
|
|
36
|
+
/** Shows progress on an agent's pill while a manual recap request runs, then its result. */
|
|
37
|
+
track<T>(agentId: string, request: Promise<T>): Promise<T>;
|
|
38
|
+
}
|
|
39
|
+
|
|
32
40
|
/**
|
|
33
41
|
* Keeps one composer pill per agent in sync with daemon recaps. Recaps finish after an idle delay
|
|
34
42
|
* without any agent update, so the list is also polled, faster right after agent activity.
|
|
43
|
+
*
|
|
44
|
+
* A factory rather than a class: plugin client bundles reach Hermes (iOS, Android) without Metro's
|
|
45
|
+
* transforms, and Hermes rejects class syntax (getpaseo/paseo#5783).
|
|
35
46
|
*/
|
|
36
|
-
export
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
#activeUntil = 0;
|
|
46
|
-
readonly #popover = makeRecapPopover({
|
|
47
|
-
cachedView: (agentId) => this.#views.get(agentId),
|
|
48
|
-
track: (agentId, request) => this.track(agentId, request),
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
constructor(client: PluginClientContext) {
|
|
52
|
-
this.#client = client;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
start(): void {
|
|
56
|
-
this.#client.paseo.agents
|
|
57
|
-
.list({ subscribe: {}, signal: this.#lifetime.signal })
|
|
58
|
-
.then(({ subscription }) => {
|
|
59
|
-
subscription.subscribe({
|
|
60
|
-
snapshot: ({ entries }) => {
|
|
61
|
-
this.#removeAll();
|
|
62
|
-
for (const { agent } of entries) this.#register(agent);
|
|
63
|
-
this.#scheduleRefresh();
|
|
64
|
-
},
|
|
65
|
-
update: (message) => {
|
|
66
|
-
if (message.type !== "agent_update") return;
|
|
67
|
-
const update = message.payload;
|
|
68
|
-
if (update.kind === "remove") this.#remove(update.agentId);
|
|
69
|
-
else if (!this.#pills.has(update.agent.id)) this.#register(update.agent);
|
|
70
|
-
this.#activeUntil = Date.now() + ACTIVE_WINDOW_MS;
|
|
71
|
-
this.#scheduleRefresh();
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
})
|
|
75
|
-
.catch((error: unknown) => {
|
|
76
|
-
if (!this.#lifetime.signal.aborted) console.error("[paseo-recap] agent observation failed", error);
|
|
77
|
-
});
|
|
78
|
-
this.#poll = setInterval(() => {
|
|
79
|
-
const now = Date.now();
|
|
80
|
-
const pending = [...this.#views.values()].some(isPending);
|
|
81
|
-
if (pending || now < this.#activeUntil || now - this.#lastRefreshAt >= IDLE_POLL_MS) {
|
|
82
|
-
void this.refresh();
|
|
83
|
-
}
|
|
84
|
-
}, TICK_MS);
|
|
85
|
-
}
|
|
47
|
+
export function createRecapPills(client: PluginClientContext): RecapPills {
|
|
48
|
+
const pills = new Map<string, PluginButtonRegistration>();
|
|
49
|
+
const lifetime = new AbortController();
|
|
50
|
+
let views = new Map<string, RecapView>();
|
|
51
|
+
let debounce: ReturnType<typeof setTimeout> | null = null;
|
|
52
|
+
let poll: ReturnType<typeof setInterval> | null = null;
|
|
53
|
+
let refreshing = false;
|
|
54
|
+
let lastRefreshAt = 0;
|
|
55
|
+
let activeUntil = 0;
|
|
86
56
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
57
|
+
const render = (): void => {
|
|
58
|
+
const now = Date.now();
|
|
59
|
+
for (const [agentId, pill] of pills) {
|
|
60
|
+
pill.update(pillButton(pillPresentation(views.get(agentId), now)));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const refresh = async (): Promise<void> => {
|
|
65
|
+
if (refreshing || lifetime.signal.aborted) return;
|
|
66
|
+
refreshing = true;
|
|
67
|
+
lastRefreshAt = Date.now();
|
|
91
68
|
try {
|
|
92
|
-
const { recaps } = await
|
|
93
|
-
|
|
94
|
-
|
|
69
|
+
const { recaps } = await client.rpc(recapListRpc, {});
|
|
70
|
+
views = new Map(recaps.map((view) => [view.agentId, view]));
|
|
71
|
+
render();
|
|
95
72
|
} catch (error) {
|
|
96
73
|
console.error("[paseo-recap] failed to load recaps", error);
|
|
97
74
|
} finally {
|
|
98
|
-
|
|
75
|
+
refreshing = false;
|
|
99
76
|
}
|
|
100
|
-
}
|
|
77
|
+
};
|
|
101
78
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
this.#render();
|
|
79
|
+
const track = async <T,>(agentId: string, request: Promise<T>): Promise<T> => {
|
|
80
|
+
const view = views.get(agentId) ?? { agentId, recap: null, previous: [], error: null, state: "idle" };
|
|
81
|
+
views.set(agentId, { ...view, state: "generating", error: null });
|
|
82
|
+
render();
|
|
107
83
|
try {
|
|
108
84
|
return await request;
|
|
109
85
|
} finally {
|
|
110
|
-
void
|
|
86
|
+
void refresh();
|
|
111
87
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
#register(agent: { id: string; workspaceId?: string | null }): void {
|
|
122
|
-
if (this.#lifetime.signal.aborted || !agent.workspaceId) return;
|
|
123
|
-
this.#pills.get(agent.id)?.remove();
|
|
124
|
-
const registration = this.#client.addComposerPill({
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const popover = makeRecapPopover({ cachedView: (agentId) => views.get(agentId), track });
|
|
91
|
+
|
|
92
|
+
const register = (agent: { id: string; workspaceId?: string | null }): void => {
|
|
93
|
+
if (lifetime.signal.aborted || !agent.workspaceId) return;
|
|
94
|
+
pills.get(agent.id)?.remove();
|
|
95
|
+
const registration = client.addComposerPill({
|
|
125
96
|
id: "recap",
|
|
126
97
|
workspaceId: agent.workspaceId,
|
|
127
98
|
agentId: agent.id,
|
|
128
99
|
button: {
|
|
129
100
|
title: "Session recap",
|
|
130
|
-
...pillButton(pillPresentation(
|
|
131
|
-
behavior: { kind: "popover", Content:
|
|
101
|
+
...pillButton(pillPresentation(views.get(agent.id), Date.now())),
|
|
102
|
+
behavior: { kind: "popover", Content: popover },
|
|
132
103
|
},
|
|
133
104
|
});
|
|
134
|
-
|
|
135
|
-
}
|
|
105
|
+
pills.set(agent.id, registration);
|
|
106
|
+
};
|
|
136
107
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
108
|
+
const remove = (agentId: string): void => {
|
|
109
|
+
pills.get(agentId)?.remove();
|
|
110
|
+
pills.delete(agentId);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const removeAll = (): void => {
|
|
114
|
+
for (const pill of pills.values()) pill.remove();
|
|
115
|
+
pills.clear();
|
|
116
|
+
};
|
|
143
117
|
|
|
144
|
-
|
|
145
|
-
if (
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
void
|
|
118
|
+
const scheduleRefresh = (): void => {
|
|
119
|
+
if (debounce) clearTimeout(debounce);
|
|
120
|
+
debounce = setTimeout(() => {
|
|
121
|
+
debounce = null;
|
|
122
|
+
void refresh();
|
|
149
123
|
}, UPDATE_DEBOUNCE_MS);
|
|
150
|
-
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const start = (): void => {
|
|
127
|
+
client.paseo.agents
|
|
128
|
+
.list({ subscribe: {}, signal: lifetime.signal })
|
|
129
|
+
.then(({ subscription }) => {
|
|
130
|
+
subscription.subscribe({
|
|
131
|
+
snapshot: ({ entries }) => {
|
|
132
|
+
removeAll();
|
|
133
|
+
for (const { agent } of entries) register(agent);
|
|
134
|
+
scheduleRefresh();
|
|
135
|
+
},
|
|
136
|
+
update: (message) => {
|
|
137
|
+
if (message.type !== "agent_update") return;
|
|
138
|
+
const update = message.payload;
|
|
139
|
+
if (update.kind === "remove") remove(update.agentId);
|
|
140
|
+
else if (!pills.has(update.agent.id)) register(update.agent);
|
|
141
|
+
activeUntil = Date.now() + ACTIVE_WINDOW_MS;
|
|
142
|
+
scheduleRefresh();
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
})
|
|
146
|
+
.catch((error: unknown) => {
|
|
147
|
+
if (!lifetime.signal.aborted) console.error("[paseo-recap] agent observation failed", error);
|
|
148
|
+
});
|
|
149
|
+
poll = setInterval(() => {
|
|
150
|
+
const now = Date.now();
|
|
151
|
+
const pending = [...views.values()].some(isPending);
|
|
152
|
+
if (pending || now < activeUntil || now - lastRefreshAt >= IDLE_POLL_MS) void refresh();
|
|
153
|
+
}, TICK_MS);
|
|
154
|
+
};
|
|
151
155
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
+
const stop = (): void => {
|
|
157
|
+
lifetime.abort();
|
|
158
|
+
if (debounce) clearTimeout(debounce);
|
|
159
|
+
if (poll) clearInterval(poll);
|
|
160
|
+
removeAll();
|
|
161
|
+
};
|
|
156
162
|
|
|
157
|
-
|
|
158
|
-
for (const pill of this.#pills.values()) pill.remove();
|
|
159
|
-
this.#pills.clear();
|
|
160
|
-
}
|
|
163
|
+
return { start, stop, refresh, track };
|
|
161
164
|
}
|
package/index.client.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
2
2
|
import { RecapLine } from "./client/recap-line";
|
|
3
|
-
import {
|
|
3
|
+
import { createRecapPills } from "./client/pills";
|
|
4
4
|
import { RecapSettingsScreen } from "./client/settings-screen";
|
|
5
5
|
import { RECAP_TIMELINE_KIND, RecapTimelineDataSchema, recapRegenerateRpc } from "./shared/recap";
|
|
6
6
|
|
|
7
7
|
export default function contribute(client: PluginClientContext) {
|
|
8
|
-
const pills =
|
|
8
|
+
const pills = createRecapPills(client);
|
|
9
9
|
pills.start();
|
|
10
10
|
|
|
11
11
|
const removeTimelineRenderer = client.addTimelineRenderer({
|
package/package.json
CHANGED