@koinzhang/paseo-plugin-activity 0.2.0 → 0.4.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.
- package/CHANGELOG.md +50 -1
- package/README.md +26 -11
- package/client/attention-agents.test.ts +94 -0
- package/client/attention-agents.ts +67 -0
- package/client/attention-pill.tsx +254 -0
- package/client/attention-popover.tsx +161 -0
- package/client/attention-status-store.ts +47 -0
- package/client/formatted-time.tsx +23 -0
- package/client/global-surface.tsx +3 -1
- package/client/hidden-pill-recheck.test.ts +33 -0
- package/client/hidden-pill-recheck.ts +22 -0
- package/client/latest-user-message.test.ts +34 -0
- package/client/latest-user-message.ts +96 -0
- package/client/open-agent.ts +32 -0
- package/client/panel.tsx +117 -107
- package/client/pill-directory.test.ts +92 -0
- package/client/pill-directory.ts +79 -0
- package/client/pill.tsx +23 -23
- package/client/usage-popover.tsx +75 -84
- package/client/usage-query.tsx +8 -3
- package/client/usage-stats.tsx +2 -2
- package/client/use-agent-turn-end.ts +72 -0
- package/client/use-latest-user-message.ts +15 -0
- package/client/use-workspace-agent-statuses.ts +47 -0
- package/client/workspace/agent-live-status-sync.tsx +103 -0
- package/client/workspace/agent-row.tsx +105 -28
- package/client/workspace/agents-section.tsx +92 -17
- package/client/workspace/constants.test.ts +66 -0
- package/client/workspace/constants.ts +66 -4
- package/client/workspace/filters.test.ts +59 -0
- package/client/workspace/filters.ts +11 -2
- package/client/workspace/list-host-agents.test.ts +103 -0
- package/client/workspace/list-host-agents.ts +113 -23
- package/client/workspace/panel.tsx +192 -12
- package/client/workspace/rank-section.tsx +36 -26
- package/client/workspace/running-indicator.tsx +54 -0
- package/client/workspace/status-cache.test.ts +62 -0
- package/client/workspace/status-cache.ts +23 -0
- package/client/workspace/terminal-preview.test.ts +17 -0
- package/client/workspace/terminal-preview.ts +10 -0
- package/client/workspace/terminals-section.tsx +155 -0
- package/index.client.tsx +7 -1
- package/index.server.ts +2 -0
- package/package.json +3 -3
- package/server/agents.test.ts +16 -0
- package/server/agents.ts +7 -4
- package/server/handlers-query.test.ts +24 -3
- package/server/handlers.ts +17 -5
- package/server/skill-path.ts +3 -20
- package/shared/explorer-agent-display.ts +1 -1
- package/shared/format.test.ts +35 -31
- package/shared/format.ts +21 -36
- package/shared/home-path.ts +19 -0
- package/shared/usage.test.ts +8 -2
- package/shared/usage.ts +16 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type PluginButtonContentProps,
|
|
3
|
+
useAgent,
|
|
4
|
+
} from "@getpaseo/plugin/client";
|
|
5
|
+
import { useEffect, useMemo, type ReactNode } from "react";
|
|
6
|
+
import { Text, View, type TextStyle, type ViewStyle } from "react-native";
|
|
7
|
+
import {
|
|
8
|
+
filterAttentionAgents,
|
|
9
|
+
type AttentionAgentItem,
|
|
10
|
+
} from "./attention-agents.ts";
|
|
11
|
+
import { openAttentionAgent } from "./open-agent.ts";
|
|
12
|
+
import { useLatestUserMessagePreview } from "./use-latest-user-message.ts";
|
|
13
|
+
import { useAttentionStatuses } from "./attention-status-store.ts";
|
|
14
|
+
import { AgentRow, type AgentRowStyles } from "./workspace/agent-row.tsx";
|
|
15
|
+
|
|
16
|
+
function AttentionRow({
|
|
17
|
+
item,
|
|
18
|
+
theme,
|
|
19
|
+
styles,
|
|
20
|
+
onOpen,
|
|
21
|
+
}: {
|
|
22
|
+
item: AttentionAgentItem;
|
|
23
|
+
theme: PluginButtonContentProps["theme"];
|
|
24
|
+
styles: AgentRowStyles;
|
|
25
|
+
onOpen: () => void;
|
|
26
|
+
}): ReactNode {
|
|
27
|
+
const title = useAgent(item.agentId, (agent) => agent.title);
|
|
28
|
+
const preview = useLatestUserMessagePreview(item.agentId);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (preview.isError) {
|
|
31
|
+
console.warn("[activity] latest user message preview failed", item.agentId, preview.error);
|
|
32
|
+
}
|
|
33
|
+
}, [preview.isError, preview.error, item.agentId]);
|
|
34
|
+
|
|
35
|
+
const meta =
|
|
36
|
+
preview.data ??
|
|
37
|
+
(preview.isLoading ? "…" : null);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<AgentRow
|
|
41
|
+
label={title ?? item.agentId}
|
|
42
|
+
archived={false}
|
|
43
|
+
canOpen
|
|
44
|
+
meta={meta}
|
|
45
|
+
permissionCount={item.permissionCount}
|
|
46
|
+
attentionKind={item.kind}
|
|
47
|
+
running={false}
|
|
48
|
+
busy={false}
|
|
49
|
+
actionDisabled
|
|
50
|
+
theme={theme}
|
|
51
|
+
styles={styles}
|
|
52
|
+
onOpen={onOpen}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Popover body: other agents in this workspace that need attention. */
|
|
58
|
+
export function AttentionPopover(props: PluginButtonContentProps) {
|
|
59
|
+
if (props.context !== "agent") {
|
|
60
|
+
return (
|
|
61
|
+
<Text style={{ color: props.theme.colors.foregroundMuted }}>
|
|
62
|
+
Attention is only available for an agent
|
|
63
|
+
</Text>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return <AttentionPopoverAgent {...props} context="agent" />;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function AttentionPopoverAgent(
|
|
70
|
+
props: PluginButtonContentProps & { context: "agent" },
|
|
71
|
+
) {
|
|
72
|
+
const { theme, workspaceId, agentId, close } = props;
|
|
73
|
+
const statuses = useAttentionStatuses(workspaceId);
|
|
74
|
+
const items = useMemo(
|
|
75
|
+
() => filterAttentionAgents(statuses, agentId),
|
|
76
|
+
[statuses, agentId],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const styles = useMemo(() => {
|
|
80
|
+
const row: ViewStyle = {
|
|
81
|
+
flexDirection: "row",
|
|
82
|
+
alignItems: "center",
|
|
83
|
+
gap: 10,
|
|
84
|
+
paddingVertical: 6,
|
|
85
|
+
};
|
|
86
|
+
const title: TextStyle = {
|
|
87
|
+
color: theme.colors.foreground,
|
|
88
|
+
fontSize: 14,
|
|
89
|
+
fontWeight: "500",
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
agentListRow: row,
|
|
93
|
+
agentIconWrap: {
|
|
94
|
+
width: 18,
|
|
95
|
+
height: 18,
|
|
96
|
+
alignItems: "center",
|
|
97
|
+
justifyContent: "center",
|
|
98
|
+
} satisfies ViewStyle,
|
|
99
|
+
runningBadge: { display: "none" } as ViewStyle,
|
|
100
|
+
subAgentBadge: { display: "none" } as ViewStyle,
|
|
101
|
+
subAgentBadgeText: { display: "none" } as TextStyle,
|
|
102
|
+
listMain: { flex: 1, minWidth: 0, gap: 3 } satisfies ViewStyle,
|
|
103
|
+
listLink: title,
|
|
104
|
+
listTitle: title,
|
|
105
|
+
listMeta: {
|
|
106
|
+
color: theme.colors.foregroundMuted,
|
|
107
|
+
fontSize: 12,
|
|
108
|
+
} satisfies TextStyle,
|
|
109
|
+
titleAction: { width: 0, height: 0 } satisfies ViewStyle,
|
|
110
|
+
permissionBadge: {
|
|
111
|
+
flexDirection: "row",
|
|
112
|
+
alignItems: "center",
|
|
113
|
+
gap: 3,
|
|
114
|
+
height: 18,
|
|
115
|
+
paddingHorizontal: 5,
|
|
116
|
+
borderRadius: 9,
|
|
117
|
+
borderWidth: 1,
|
|
118
|
+
borderColor: theme.colors.border,
|
|
119
|
+
backgroundColor: theme.colors.surface1,
|
|
120
|
+
flexShrink: 0,
|
|
121
|
+
} satisfies ViewStyle,
|
|
122
|
+
permissionBadgeText: {
|
|
123
|
+
color: theme.colors.statusWarning,
|
|
124
|
+
fontSize: 11,
|
|
125
|
+
fontWeight: "600",
|
|
126
|
+
fontVariant: ["tabular-nums"],
|
|
127
|
+
} satisfies TextStyle,
|
|
128
|
+
} satisfies AgentRowStyles;
|
|
129
|
+
}, [theme]);
|
|
130
|
+
|
|
131
|
+
if (!statuses) {
|
|
132
|
+
return (
|
|
133
|
+
<Text style={{ color: theme.colors.foregroundMuted }}>Loading…</Text>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (items.length === 0) {
|
|
138
|
+
return (
|
|
139
|
+
<Text style={{ color: theme.colors.foregroundMuted }}>
|
|
140
|
+
No other agents need attention
|
|
141
|
+
</Text>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
<View style={{ gap: 2, minWidth: 240 }}>
|
|
147
|
+
{items.map((item) => (
|
|
148
|
+
<AttentionRow
|
|
149
|
+
key={item.agentId}
|
|
150
|
+
item={item}
|
|
151
|
+
theme={theme}
|
|
152
|
+
styles={styles}
|
|
153
|
+
onOpen={() => {
|
|
154
|
+
openAttentionAgent(item.agentId);
|
|
155
|
+
close();
|
|
156
|
+
}}
|
|
157
|
+
/>
|
|
158
|
+
))}
|
|
159
|
+
</View>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
import type { AgentStatusInfo } from "./workspace/constants.ts";
|
|
3
|
+
|
|
4
|
+
const byWorkspace = new Map<string, Record<string, AgentStatusInfo>>();
|
|
5
|
+
const listeners = new Set<() => void>();
|
|
6
|
+
|
|
7
|
+
function emit(): void {
|
|
8
|
+
for (const listener of listeners) listener();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function subscribe(listener: () => void): () => void {
|
|
12
|
+
listeners.add(listener);
|
|
13
|
+
return () => {
|
|
14
|
+
listeners.delete(listener);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Publish push/poll status for a workspace; icon + popover read this immediately. */
|
|
19
|
+
export function publishAttentionStatuses(
|
|
20
|
+
workspaceId: string,
|
|
21
|
+
statuses: Record<string, AgentStatusInfo>,
|
|
22
|
+
): void {
|
|
23
|
+
byWorkspace.set(workspaceId, statuses);
|
|
24
|
+
emit();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getAttentionStatuses(
|
|
28
|
+
workspaceId: string,
|
|
29
|
+
): Record<string, AgentStatusInfo> | undefined {
|
|
30
|
+
return byWorkspace.get(workspaceId);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function clearAttentionStatuses(): void {
|
|
34
|
+
byWorkspace.clear();
|
|
35
|
+
emit();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Re-renders when contribute-layer status for this workspace is republished. */
|
|
39
|
+
export function useAttentionStatuses(
|
|
40
|
+
workspaceId: string,
|
|
41
|
+
): Record<string, AgentStatusInfo> | undefined {
|
|
42
|
+
return useSyncExternalStore(
|
|
43
|
+
subscribe,
|
|
44
|
+
() => byWorkspace.get(workspaceId),
|
|
45
|
+
() => undefined,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { Text, type TextStyle } from "react-native";
|
|
3
|
+
import { formatActivityTime } from "../shared/format.ts";
|
|
4
|
+
import { useAppLanguage } from "./use-app-language.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ISO timestamp with app language (fallback `en`) + Intl locale style.
|
|
8
|
+
* Today → time only; same year → month/day + time; otherwise includes the year.
|
|
9
|
+
*/
|
|
10
|
+
export function FormattedTime({
|
|
11
|
+
iso,
|
|
12
|
+
style,
|
|
13
|
+
prefix,
|
|
14
|
+
}: {
|
|
15
|
+
iso: string | null | undefined;
|
|
16
|
+
style?: TextStyle;
|
|
17
|
+
/** e.g. `"Last "` — concatenated before the stamp */
|
|
18
|
+
prefix?: string;
|
|
19
|
+
}): ReactNode {
|
|
20
|
+
const locale = useAppLanguage();
|
|
21
|
+
const stamp = formatActivityTime(iso, locale);
|
|
22
|
+
return <Text style={style}>{prefix ? `${prefix}${stamp}` : stamp}</Text>;
|
|
23
|
+
}
|
|
@@ -30,6 +30,7 @@ import { selectProviderOptions } from "./provider-filter.ts";
|
|
|
30
30
|
import { useAppLanguage } from "./use-app-language.ts";
|
|
31
31
|
import { buildActivityInsights, ACTIVITY_LIST_LIMIT } from "../shared/insights.ts";
|
|
32
32
|
import { rangeFrom, RANGE_OPTIONS, type RangeId } from "./range.ts";
|
|
33
|
+
import { useRegisterOpenAgent } from "./open-agent.ts";
|
|
33
34
|
|
|
34
35
|
/** Max rows for Activity insights and Most used skills / MCP. */
|
|
35
36
|
const LIST_LIMIT = ACTIVITY_LIST_LIMIT;
|
|
@@ -211,7 +212,8 @@ function RankList({
|
|
|
211
212
|
);
|
|
212
213
|
}
|
|
213
214
|
|
|
214
|
-
export function GlobalUsageSurface({ theme, layout }: PluginSurfaceProps) {
|
|
215
|
+
export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceProps) {
|
|
216
|
+
useRegisterOpenAgent(navigation?.openAgent);
|
|
215
217
|
const [range, setRange] = useState<RangeId>("all");
|
|
216
218
|
const [providerFilter, setProviderFilter] = useState<string>("all");
|
|
217
219
|
const [heatmapMode, setHeatmapMode] = useState<HeatmapMode>("daily");
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { createHiddenPillRecheck } from "./hidden-pill-recheck.ts";
|
|
4
|
+
import type { UsagePillData } from "./pill-data-cache.ts";
|
|
5
|
+
const empty: UsagePillData = { skills: [], mcpTools: [] };
|
|
6
|
+
const populated: UsagePillData = { skills: [], mcpTools: [{ server: "paseo", tool: "read", count: 1, failures: 0, lastUsedAt: null }] };
|
|
7
|
+
|
|
8
|
+
test("hidden empty pill stays hidden, but delayed ingestion can show it", async () => {
|
|
9
|
+
let data = empty;
|
|
10
|
+
let shows = 0;
|
|
11
|
+
const check = createHiddenPillRecheck(async () => data, () => true, () => { shows++; });
|
|
12
|
+
await check(); await check();
|
|
13
|
+
assert.equal(shows, 0);
|
|
14
|
+
data = populated;
|
|
15
|
+
await check();
|
|
16
|
+
assert.equal(shows, 1);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("hidden rechecks coalesce and cannot show a removed pill", async () => {
|
|
20
|
+
let finish!: (data: UsagePillData) => void;
|
|
21
|
+
let current = true;
|
|
22
|
+
let loads = 0;
|
|
23
|
+
let shows = 0;
|
|
24
|
+
const check = createHiddenPillRecheck(() => { loads++; return new Promise(resolve => { finish = resolve; }); },
|
|
25
|
+
() => current, () => { shows++; });
|
|
26
|
+
const first = check();
|
|
27
|
+
await check();
|
|
28
|
+
assert.equal(loads, 1);
|
|
29
|
+
current = false;
|
|
30
|
+
finish(populated);
|
|
31
|
+
await first;
|
|
32
|
+
assert.equal(shows, 0);
|
|
33
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { pillDataIsEmpty, type UsagePillData } from "./pill-data-cache.ts";
|
|
2
|
+
|
|
3
|
+
/** Recheck hidden pills without showing empty chrome; discard results after removal. */
|
|
4
|
+
export function createHiddenPillRecheck(
|
|
5
|
+
load: () => Promise<UsagePillData>,
|
|
6
|
+
isCurrentAndHidden: () => boolean,
|
|
7
|
+
show: (data: UsagePillData) => void,
|
|
8
|
+
): () => Promise<void> {
|
|
9
|
+
let running = false;
|
|
10
|
+
return async () => {
|
|
11
|
+
if (running || !isCurrentAndHidden()) return;
|
|
12
|
+
running = true;
|
|
13
|
+
try {
|
|
14
|
+
const data = await load();
|
|
15
|
+
if (isCurrentAndHidden() && !pillDataIsEmpty(data)) show(data);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (isCurrentAndHidden()) console.error("[activity] hidden pill recheck failed", error);
|
|
18
|
+
} finally {
|
|
19
|
+
running = false;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import {
|
|
4
|
+
formatMessagePreview,
|
|
5
|
+
pickLatestUserMessageText,
|
|
6
|
+
} from "./latest-user-message.ts";
|
|
7
|
+
|
|
8
|
+
describe("pickLatestUserMessageText", () => {
|
|
9
|
+
it("picks the highest-seq non-empty user_message", () => {
|
|
10
|
+
const text = pickLatestUserMessageText([
|
|
11
|
+
{ item: { type: "user_message", text: "first" }, seqStart: 1, timestamp: "a" },
|
|
12
|
+
{ item: { type: "assistant_message", text: "reply" }, seqStart: 2, timestamp: "b" },
|
|
13
|
+
{ item: { type: "user_message", text: " " }, seqStart: 3, timestamp: "c" },
|
|
14
|
+
{ item: { type: "user_message", text: "latest" }, seqStart: 4, timestamp: "d" },
|
|
15
|
+
]);
|
|
16
|
+
assert.equal(text, "latest");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("when seq missing, prefers later list entry", () => {
|
|
20
|
+
const text = pickLatestUserMessageText([
|
|
21
|
+
{ item: { type: "user_message", text: "older" } },
|
|
22
|
+
{ item: { type: "assistant_message", text: "reply" } },
|
|
23
|
+
{ item: { type: "user_message", text: "newer" } },
|
|
24
|
+
]);
|
|
25
|
+
assert.equal(text, "newer");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("formatMessagePreview", () => {
|
|
30
|
+
it("collapses whitespace and truncates", () => {
|
|
31
|
+
assert.equal(formatMessagePreview("hello\n world"), "hello world");
|
|
32
|
+
assert.equal(formatMessagePreview("abcdefghij", 6), "abcde…");
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural timeline entry shape for user-message previews.
|
|
3
|
+
*
|
|
4
|
+
* Do not import `@getpaseo/protocol/*` from client/: Paseo compiles plugins
|
|
5
|
+
* without installing that package, and type-only imports still fail the
|
|
6
|
+
* `paseo-plugin-client-runtime-boundary` build (see server/host-types.ts).
|
|
7
|
+
*/
|
|
8
|
+
export type TimelineTailEntry = {
|
|
9
|
+
item: {
|
|
10
|
+
type: string;
|
|
11
|
+
text?: string | null;
|
|
12
|
+
};
|
|
13
|
+
seqStart?: number;
|
|
14
|
+
timestamp?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type TimelineApi = {
|
|
18
|
+
agents: {
|
|
19
|
+
ref: (agentId: string) => {
|
|
20
|
+
timeline: {
|
|
21
|
+
refetch: (options: {
|
|
22
|
+
projection?: "canonical" | "projected";
|
|
23
|
+
direction?: "tail" | "before" | "after";
|
|
24
|
+
limit?: number;
|
|
25
|
+
}) => Promise<{
|
|
26
|
+
error?: string | null;
|
|
27
|
+
entries?: ReadonlyArray<TimelineTailEntry> | null;
|
|
28
|
+
}>;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Newest non-empty user_message; prefers higher seq/ts, else later list index (tail order). */
|
|
35
|
+
export function pickLatestUserMessageText(
|
|
36
|
+
entries: ReadonlyArray<TimelineTailEntry>,
|
|
37
|
+
): string | null {
|
|
38
|
+
let best: { text: string; seq: number; ts: string; index: number } | null = null;
|
|
39
|
+
for (let index = 0; index < entries.length; index++) {
|
|
40
|
+
const entry = entries[index]!;
|
|
41
|
+
if (entry.item.type !== "user_message") continue;
|
|
42
|
+
const text = entry.item.text?.trim();
|
|
43
|
+
if (!text) continue;
|
|
44
|
+
const seq = entry.seqStart ?? -1;
|
|
45
|
+
const ts = entry.timestamp ?? "";
|
|
46
|
+
if (
|
|
47
|
+
!best ||
|
|
48
|
+
seq > best.seq ||
|
|
49
|
+
(seq === best.seq && ts > best.ts) ||
|
|
50
|
+
(seq === best.seq && ts === best.ts && index > best.index)
|
|
51
|
+
) {
|
|
52
|
+
best = { text, seq, ts, index };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return best?.text ?? null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Single-line preview for list meta; collapses whitespace. */
|
|
59
|
+
export function formatMessagePreview(text: string, maxChars = 72): string {
|
|
60
|
+
const oneLine = text.replace(/\s+/g, " ").trim();
|
|
61
|
+
if (oneLine.length <= maxChars) return oneLine;
|
|
62
|
+
return `${oneLine.slice(0, Math.max(1, maxChars - 1)).trimEnd()}…`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function refetchPreview(
|
|
66
|
+
paseo: TimelineApi,
|
|
67
|
+
agentId: string,
|
|
68
|
+
projection: "projected" | "canonical",
|
|
69
|
+
): Promise<string | null> {
|
|
70
|
+
const page = await paseo.agents.ref(agentId).timeline.refetch({
|
|
71
|
+
projection,
|
|
72
|
+
direction: "tail",
|
|
73
|
+
limit: 80,
|
|
74
|
+
});
|
|
75
|
+
if (page.error) throw new Error(page.error);
|
|
76
|
+
const text = pickLatestUserMessageText(page.entries ?? []);
|
|
77
|
+
return text ? formatMessagePreview(text) : null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Read the newest user prompt from the host timeline (not local SQLite —
|
|
82
|
+
* message bodies are intentionally not stored in usage.db).
|
|
83
|
+
* Prefer projected (UI text), then canonical.
|
|
84
|
+
*/
|
|
85
|
+
export async function fetchLatestUserMessagePreview(
|
|
86
|
+
paseo: TimelineApi,
|
|
87
|
+
agentId: string,
|
|
88
|
+
): Promise<string | null> {
|
|
89
|
+
try {
|
|
90
|
+
const projected = await refetchPreview(paseo, agentId, "projected");
|
|
91
|
+
if (projected) return projected;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.warn("[activity] projected timeline preview failed", agentId, error);
|
|
94
|
+
}
|
|
95
|
+
return refetchPreview(paseo, agentId, "canonical");
|
|
96
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
type OpenAgent = (input: { agentId: string }) => void;
|
|
4
|
+
|
|
5
|
+
/** Last-registered wins; cleanup pops this registration only. */
|
|
6
|
+
const stack: OpenAgent[] = [];
|
|
7
|
+
|
|
8
|
+
export function setOpenAgent(open: OpenAgent | null | undefined): () => void {
|
|
9
|
+
if (!open) return () => {};
|
|
10
|
+
stack.push(open);
|
|
11
|
+
return () => {
|
|
12
|
+
const index = stack.lastIndexOf(open);
|
|
13
|
+
if (index >= 0) stack.splice(index, 1);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Register host `navigation.openAgent` while a navigable surface/panel is mounted. */
|
|
18
|
+
export function useRegisterOpenAgent(open: OpenAgent | null | undefined): void {
|
|
19
|
+
useEffect(() => setOpenAgent(open), [open]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function tryOpenAgent(agentId: string): boolean {
|
|
23
|
+
const open = stack[stack.length - 1];
|
|
24
|
+
if (!open) return false;
|
|
25
|
+
open({ agentId });
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Focus another agent conversation via the registered host navigation bridge. */
|
|
30
|
+
export function openAttentionAgent(agentId: string): void {
|
|
31
|
+
tryOpenAgent(agentId);
|
|
32
|
+
}
|