@koinzhang/paseo-plugin-activity 0.7.0 → 0.8.0

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.
@@ -0,0 +1,71 @@
1
+ import { homedir } from "node:os";
2
+ import type { PluginHookAgent, PluginHookContext } from "@getpaseo/plugin/server";
3
+ import { agentRowFromHook } from "./agents.ts";
4
+ import type { AgentTimelineItem } from "./host-types.ts";
5
+ import { ingestTimeline, ingestUserMessages } from "./ingest.ts";
6
+ import { resolveAgentModel } from "./resolve-model.ts";
7
+ import type { UsageStore } from "./store.ts";
8
+
9
+ /** Recent history is enough for immediacy; the background scan owns the full timeline. */
10
+ export const TURN_TAIL_LIMIT = 500;
11
+
12
+ type PaseoApi = PluginHookContext["paseo"];
13
+
14
+ /**
15
+ * Paseo 0.13+ sends an empty `timeline` in `agent.turn.after`, so read the recent
16
+ * history back through the SDK instead of trusting the hook payload.
17
+ */
18
+ export async function refetchTimelineTail(
19
+ paseo: PaseoApi,
20
+ agentId: string,
21
+ limit: number = TURN_TAIL_LIMIT,
22
+ ): Promise<AgentTimelineItem[]> {
23
+ const page = await paseo.agents.ref(agentId).timeline.refetch({
24
+ projection: "canonical",
25
+ direction: "tail",
26
+ limit,
27
+ });
28
+ if (page.error) throw new Error(page.error);
29
+ return page.entries.map(({ item }) => item);
30
+ }
31
+
32
+ export interface IngestTurnAfterOptions {
33
+ homeDir?: string;
34
+ }
35
+
36
+ /**
37
+ * Ingest one finished turn from a freshly read timeline tail.
38
+ *
39
+ * Returns the number of tool-call rows upserted. Calls already stored in a
40
+ * terminal status cannot change from a snapshot, so they are skipped.
41
+ */
42
+ export async function ingestTurnAfter(
43
+ store: UsageStore,
44
+ paseo: PaseoApi,
45
+ agent: PluginHookAgent,
46
+ options: IngestTurnAfterOptions = {},
47
+ ): Promise<number> {
48
+ const existing = store.getAgent(agent.id);
49
+ store.upsertAgents([
50
+ agentRowFromHook(agent, {
51
+ createdAt: existing?.createdAt,
52
+ archivedAt: existing?.archivedAt,
53
+ }),
54
+ ]);
55
+
56
+ const model = await resolveAgentModel(paseo, agent.id);
57
+ const timeline = await refetchTimelineTail(paseo, agent.id);
58
+ store.upsertUserMessages(ingestUserMessages(timeline, agent, { model }));
59
+ store.pruneReplayDuplicateMessages(agent.id);
60
+
61
+ const settled = store.terminalCallIds(agent.id);
62
+ const pending = timeline.filter(
63
+ (item) => item.type !== "tool_call" || !settled.has(item.callId),
64
+ );
65
+ const rows = ingestTimeline(pending, agent, null, {
66
+ homeDir: options.homeDir ?? homedir(),
67
+ });
68
+ if (rows.length === 0) return 0;
69
+ store.upsertMany(rows);
70
+ return rows.length;
71
+ }
@@ -18,7 +18,7 @@ export type InsightSummary = {
18
18
  chatAgents?: number;
19
19
  };
20
20
 
21
- /** Shared cap for Activity insights and Most used skills / MCP / models. */
21
+ /** Shared cap for the Workspace Activity Skills / MCP rankings. */
22
22
  export const ACTIVITY_LIST_LIMIT = 8;
23
23
 
24
24
  function formatDayLabel(dateKey: string, locale: string): string {