@howaboua/pi-agent-board 0.0.2 → 0.0.4
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 +16 -3
- package/INTEGRATION.md +7 -7
- package/README.md +24 -15
- package/dist/viewer/server.js +5 -0
- package/dist/viewer/web/app.js +29 -456
- package/dist/viewer/web/navigation.js +72 -0
- package/dist/viewer/web/posts.js +106 -0
- package/dist/viewer/web/render.js +147 -0
- package/dist/viewer/web/session.js +86 -0
- package/dist/viewer/web/updates.js +106 -0
- package/index.ts +19 -69
- package/package.json +5 -5
- package/src/briefing.ts +13 -5
- package/src/config.ts +17 -7
- package/src/consolidation.ts +32 -0
- package/src/context-briefing.ts +49 -31
- package/src/contract.ts +14 -12
- package/src/identity.ts +2 -2
- package/src/queries.ts +1 -2
- package/src/response.ts +20 -0
- package/src/runtime/catchup.ts +96 -0
- package/src/runtime/coordinator.ts +278 -0
- package/src/runtime/index.ts +113 -0
- package/src/runtime/owner.ts +139 -0
- package/src/runtime/routing.ts +137 -0
- package/src/{turns.ts → runtime/turns.ts} +3 -3
- package/src/settings/panel.ts +87 -0
- package/src/summaries.ts +7 -1
- package/src/summarizer.ts +9 -8
- package/src/tool.ts +8 -3
- package/src/viewer/server.ts +5 -0
- package/src/viewer/web/app.js +29 -456
- package/src/viewer/web/navigation.js +72 -0
- package/src/viewer/web/posts.js +106 -0
- package/src/viewer/web/render.js +147 -0
- package/src/viewer/web/session.js +86 -0
- package/src/viewer/web/updates.js +106 -0
- package/src/runtime.ts +0 -614
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { $, state, run, selectionURL } from "./session.js";
|
|
2
|
+
import {
|
|
3
|
+
node,
|
|
4
|
+
shortName,
|
|
5
|
+
author,
|
|
6
|
+
date,
|
|
7
|
+
empty,
|
|
8
|
+
statusLabel,
|
|
9
|
+
renderPost,
|
|
10
|
+
} from "./posts.js";
|
|
11
|
+
|
|
12
|
+
export function createBoardRenderer(loadList, openThread) {
|
|
13
|
+
function renderBoard() {
|
|
14
|
+
const detail = state.detail;
|
|
15
|
+
const channels = [
|
|
16
|
+
{ name: "", label: "All activity" },
|
|
17
|
+
...detail.channels.map((channel) => ({
|
|
18
|
+
name: channel.name,
|
|
19
|
+
label: channel.name,
|
|
20
|
+
posts: channel.posts,
|
|
21
|
+
})),
|
|
22
|
+
];
|
|
23
|
+
$("channels").replaceChildren(
|
|
24
|
+
...channels.map((channel) => {
|
|
25
|
+
const button = node("button", "", channel.label);
|
|
26
|
+
button.type = "button";
|
|
27
|
+
button.dataset.channel = channel.name;
|
|
28
|
+
button.setAttribute(
|
|
29
|
+
"aria-current",
|
|
30
|
+
String(state.channel === channel.name),
|
|
31
|
+
);
|
|
32
|
+
if (channel.posts !== undefined)
|
|
33
|
+
button.append(node("small", "", String(channel.posts)));
|
|
34
|
+
button.onclick = () =>
|
|
35
|
+
run(async () => {
|
|
36
|
+
state.channel = channel.name;
|
|
37
|
+
await loadList();
|
|
38
|
+
renderBoard();
|
|
39
|
+
});
|
|
40
|
+
return button;
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
// Polling never replaces focused controls when their options have not changed.
|
|
44
|
+
const options = [
|
|
45
|
+
{ name: "", label: "All agents" },
|
|
46
|
+
...detail.agents.map((agent) => ({
|
|
47
|
+
name: agent.name,
|
|
48
|
+
label: shortName(agent.name),
|
|
49
|
+
})),
|
|
50
|
+
];
|
|
51
|
+
const signature = JSON.stringify(options);
|
|
52
|
+
if ($("author").dataset.options !== signature) {
|
|
53
|
+
$("author").replaceChildren(
|
|
54
|
+
...options.map((option) => {
|
|
55
|
+
const element = node("option", "", option.label);
|
|
56
|
+
element.value = option.name;
|
|
57
|
+
element.title = option.name;
|
|
58
|
+
return element;
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
$("author").dataset.options = signature;
|
|
62
|
+
}
|
|
63
|
+
$("author").value = state.author;
|
|
64
|
+
const watching = detail.subscriptions.filter(
|
|
65
|
+
(subscription) => subscription.enabled,
|
|
66
|
+
);
|
|
67
|
+
$("subscriptions").replaceChildren(
|
|
68
|
+
...watching.map((subscription) => {
|
|
69
|
+
const line = node("p");
|
|
70
|
+
line.append(
|
|
71
|
+
author(subscription.agent),
|
|
72
|
+
document.createTextNode(` watches ${subscription.target}`),
|
|
73
|
+
);
|
|
74
|
+
return line;
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
$("watching").hidden = !watching.length;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function renderThreads() {
|
|
81
|
+
$("list-title").textContent = state.channel || "All activity";
|
|
82
|
+
$("threads").replaceChildren(
|
|
83
|
+
...state.page.threads.map((thread) => {
|
|
84
|
+
const link = node("a", "thread");
|
|
85
|
+
link.href = selectionURL(thread.id);
|
|
86
|
+
link.dataset.thread = thread.id;
|
|
87
|
+
link.setAttribute("aria-current", String(thread.id === state.thread));
|
|
88
|
+
const meta = node("div", "thread-meta");
|
|
89
|
+
meta.append(
|
|
90
|
+
author(thread.author),
|
|
91
|
+
node("span", "", date(thread.lastActivity)),
|
|
92
|
+
);
|
|
93
|
+
const foot = node("div", "thread-foot");
|
|
94
|
+
foot.append(
|
|
95
|
+
statusLabel(thread.status),
|
|
96
|
+
node("span", "", thread.channel),
|
|
97
|
+
node(
|
|
98
|
+
"span",
|
|
99
|
+
"",
|
|
100
|
+
`${thread.replies} ${thread.replies === 1 ? "reply" : "replies"}`,
|
|
101
|
+
),
|
|
102
|
+
);
|
|
103
|
+
if (thread.summarized) foot.append(node("span", "", "Summary"));
|
|
104
|
+
link.append(meta, node("p", "thread-preview", thread.preview), foot);
|
|
105
|
+
link.onclick = (event) => {
|
|
106
|
+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
|
|
107
|
+
return;
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
run(() => openThread(thread.id));
|
|
110
|
+
};
|
|
111
|
+
return link;
|
|
112
|
+
}),
|
|
113
|
+
);
|
|
114
|
+
if (!state.page.threads.length)
|
|
115
|
+
empty(
|
|
116
|
+
$("threads"),
|
|
117
|
+
state.query || state.author ? "No matches" : "No posts",
|
|
118
|
+
);
|
|
119
|
+
$("more-threads").hidden = !state.page.nextCursor;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function renderConversation() {
|
|
123
|
+
const conversation = state.conversation;
|
|
124
|
+
const summary = conversation.summary;
|
|
125
|
+
$("thread-status").replaceChildren(statusLabel(conversation.status));
|
|
126
|
+
$("discussion-mode").hidden = !summary;
|
|
127
|
+
$("full-discussion").checked = state.full;
|
|
128
|
+
const snapshot = $("summary-snapshot");
|
|
129
|
+
snapshot.hidden = !summary;
|
|
130
|
+
snapshot.textContent = summary
|
|
131
|
+
? `Summary saved ${date(summary.createdAt)} · ${summary.provider}/${summary.model} · ${summary.reasoning} · Through ${summary.throughMessageId}`
|
|
132
|
+
: "";
|
|
133
|
+
if (summary?.hasNewerPosts)
|
|
134
|
+
snapshot.prepend(node("strong", "", "New replies after this summary. "));
|
|
135
|
+
$("posts").replaceChildren(
|
|
136
|
+
...(conversation.root
|
|
137
|
+
? [renderPost(conversation.root, true)]
|
|
138
|
+
: summary
|
|
139
|
+
? [renderPost(summary, false, true)]
|
|
140
|
+
: []),
|
|
141
|
+
...conversation.replies.map((post) => renderPost(post, false)),
|
|
142
|
+
);
|
|
143
|
+
$("more-replies").hidden = !conversation.nextCursor;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return { renderBoard, renderThreads, renderConversation };
|
|
147
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export const $ = (id) => document.getElementById(id);
|
|
2
|
+
export const fragment = new URLSearchParams(location.hash.slice(1));
|
|
3
|
+
export const token = fragment.get("view");
|
|
4
|
+
export const state = {
|
|
5
|
+
board: "",
|
|
6
|
+
channel: "",
|
|
7
|
+
author: "",
|
|
8
|
+
query: "",
|
|
9
|
+
searchFull: false,
|
|
10
|
+
full: false,
|
|
11
|
+
thread: "",
|
|
12
|
+
detail: null,
|
|
13
|
+
page: null,
|
|
14
|
+
conversation: null,
|
|
15
|
+
firstPage: null,
|
|
16
|
+
firstConversation: null,
|
|
17
|
+
threadPages: 1,
|
|
18
|
+
replyPages: 1,
|
|
19
|
+
};
|
|
20
|
+
let queue = Promise.resolve();
|
|
21
|
+
export let busy = 0;
|
|
22
|
+
export let changed = false;
|
|
23
|
+
|
|
24
|
+
export function run(action) {
|
|
25
|
+
busy++;
|
|
26
|
+
queue = queue.then(async () => {
|
|
27
|
+
try {
|
|
28
|
+
await action();
|
|
29
|
+
$("status").textContent = "";
|
|
30
|
+
} catch (error) {
|
|
31
|
+
$("status").textContent = error.message;
|
|
32
|
+
} finally {
|
|
33
|
+
busy--;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return queue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function api(path, params = {}) {
|
|
40
|
+
const url = new URL(path, location.origin);
|
|
41
|
+
for (const [key, value] of Object.entries(params))
|
|
42
|
+
if (value) url.searchParams.set(key, value);
|
|
43
|
+
const response = await fetch(url, {
|
|
44
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
45
|
+
cache: "no-store",
|
|
46
|
+
signal: AbortSignal.timeout(10_000),
|
|
47
|
+
});
|
|
48
|
+
const data = await response.json();
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
if (response.status === 401) $("live").checked = false;
|
|
51
|
+
throw new Error(
|
|
52
|
+
typeof data.error === "string"
|
|
53
|
+
? data.error
|
|
54
|
+
: `Request failed (${response.status}).`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function selectionURL(thread = state.thread) {
|
|
61
|
+
const params = new URLSearchParams();
|
|
62
|
+
params.set("view", token);
|
|
63
|
+
if (state.board) params.set("board", state.board);
|
|
64
|
+
if (thread) params.set("thread", thread);
|
|
65
|
+
return `#${params}`;
|
|
66
|
+
}
|
|
67
|
+
export function saveSelection() {
|
|
68
|
+
history.replaceState(null, "", selectionURL());
|
|
69
|
+
}
|
|
70
|
+
export function threadParams() {
|
|
71
|
+
return {
|
|
72
|
+
boardId: state.board,
|
|
73
|
+
channel: state.channel,
|
|
74
|
+
author: state.author,
|
|
75
|
+
q: state.query,
|
|
76
|
+
full: state.searchFull ? "true" : "",
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export function same(a, b) {
|
|
80
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function setChanged(value) {
|
|
84
|
+
changed = value;
|
|
85
|
+
$("refresh").textContent = value ? "New activity · Refresh" : "Refresh";
|
|
86
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { $, state, api, threadParams, setChanged, same } from "./session.js";
|
|
2
|
+
import { renderPost } from "./posts.js";
|
|
3
|
+
|
|
4
|
+
export function createUpdates({
|
|
5
|
+
renderBoard,
|
|
6
|
+
renderThreads,
|
|
7
|
+
renderConversation,
|
|
8
|
+
}) {
|
|
9
|
+
async function refresh(explicit = false) {
|
|
10
|
+
const focused = document.activeElement;
|
|
11
|
+
const focusKey =
|
|
12
|
+
focused?.dataset?.channel !== undefined
|
|
13
|
+
? ["channel", focused.dataset.channel]
|
|
14
|
+
: focused?.dataset?.thread
|
|
15
|
+
? ["thread", focused.dataset.thread]
|
|
16
|
+
: null;
|
|
17
|
+
const params = threadParams();
|
|
18
|
+
const [detail, page, conversation] = await Promise.all([
|
|
19
|
+
api("/api/board", { boardId: state.board }),
|
|
20
|
+
api("/api/threads", params),
|
|
21
|
+
state.thread
|
|
22
|
+
? api("/api/thread", {
|
|
23
|
+
boardId: state.board,
|
|
24
|
+
id: state.thread,
|
|
25
|
+
full: state.full ? "true" : "",
|
|
26
|
+
})
|
|
27
|
+
: Promise.resolve(null),
|
|
28
|
+
]);
|
|
29
|
+
if (!explicit && (state.threadPages > 1 || state.replyPages > 1)) {
|
|
30
|
+
// Compare only loaded first pages. Never splice fresh cursors into an old tail.
|
|
31
|
+
if (
|
|
32
|
+
!same(detail, state.detail) ||
|
|
33
|
+
!same(page, state.firstPage) ||
|
|
34
|
+
!same(conversation, state.firstConversation)
|
|
35
|
+
)
|
|
36
|
+
setChanged(true);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!same(detail, state.detail)) {
|
|
40
|
+
state.detail = detail;
|
|
41
|
+
renderBoard();
|
|
42
|
+
}
|
|
43
|
+
if (!same(page, state.page)) {
|
|
44
|
+
state.page = page;
|
|
45
|
+
renderThreads();
|
|
46
|
+
}
|
|
47
|
+
if (conversation && !same(conversation, state.conversation)) {
|
|
48
|
+
state.conversation = conversation;
|
|
49
|
+
renderConversation();
|
|
50
|
+
}
|
|
51
|
+
state.threadPages = 1;
|
|
52
|
+
state.replyPages = 1;
|
|
53
|
+
state.firstPage = page;
|
|
54
|
+
state.firstConversation = conversation;
|
|
55
|
+
setChanged(false);
|
|
56
|
+
if (focusKey && !focused.isConnected) {
|
|
57
|
+
const target = [
|
|
58
|
+
...document.querySelectorAll(`[data-${focusKey[0]}]`),
|
|
59
|
+
].find((element) => element.dataset[focusKey[0]] === focusKey[1]);
|
|
60
|
+
target?.focus({ preventScroll: true });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function moreThreads() {
|
|
65
|
+
if (!state.page.nextCursor) return;
|
|
66
|
+
const page = await api("/api/threads", {
|
|
67
|
+
...threadParams(),
|
|
68
|
+
cursor: state.page.nextCursor,
|
|
69
|
+
});
|
|
70
|
+
if (state.threadPages === 1) state.firstPage = state.page;
|
|
71
|
+
state.page = {
|
|
72
|
+
threads: [
|
|
73
|
+
...state.page.threads,
|
|
74
|
+
...page.threads.filter(
|
|
75
|
+
(thread) => !state.page.threads.some((old) => old.id === thread.id),
|
|
76
|
+
),
|
|
77
|
+
],
|
|
78
|
+
nextCursor: page.nextCursor,
|
|
79
|
+
};
|
|
80
|
+
state.threadPages++;
|
|
81
|
+
renderThreads();
|
|
82
|
+
}
|
|
83
|
+
async function moreReplies() {
|
|
84
|
+
if (!state.conversation.nextCursor) return;
|
|
85
|
+
const page = await api("/api/thread", {
|
|
86
|
+
boardId: state.board,
|
|
87
|
+
id: state.thread,
|
|
88
|
+
full: state.full ? "true" : "",
|
|
89
|
+
cursor: state.conversation.nextCursor,
|
|
90
|
+
});
|
|
91
|
+
if (state.replyPages === 1) state.firstConversation = state.conversation;
|
|
92
|
+
const replies = page.replies.filter(
|
|
93
|
+
(post) => !state.conversation.replies.some((old) => old.id === post.id),
|
|
94
|
+
);
|
|
95
|
+
state.conversation = {
|
|
96
|
+
...state.conversation,
|
|
97
|
+
replies: [...state.conversation.replies, ...replies],
|
|
98
|
+
nextCursor: page.nextCursor,
|
|
99
|
+
};
|
|
100
|
+
state.replyPages++;
|
|
101
|
+
$("posts").append(...replies.map((post) => renderPost(post, false)));
|
|
102
|
+
$("more-replies").hidden = !page.nextCursor;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return { refresh, moreThreads, moreReplies };
|
|
106
|
+
}
|