@openlegion/platform 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +1189 -2
- package/dist/body.d.ts +9 -0
- package/dist/body.js +28 -0
- package/dist/chat-history.d.ts +53 -0
- package/dist/chat-history.js +11 -0
- package/dist/client.d.ts +217 -0
- package/dist/client.js +367 -0
- package/dist/core.d.ts +47 -0
- package/dist/core.js +1 -0
- package/dist/crypto.d.ts +25 -0
- package/dist/crypto.js +81 -0
- package/dist/errors.d.ts +111 -0
- package/dist/errors.js +134 -0
- package/dist/events.d.ts +131 -0
- package/dist/events.js +5 -0
- package/dist/generated/api.d.ts +5505 -0
- package/dist/generated/api.js +446 -0
- package/dist/handler.d.ts +201 -0
- package/dist/handler.js +682 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +12 -0
- package/dist/kit-agents.d.ts +95 -0
- package/dist/kit-agents.js +280 -0
- package/dist/kit-codes.d.ts +279 -0
- package/dist/kit-codes.js +44 -0
- package/dist/kit-connections.d.ts +21 -0
- package/dist/kit-connections.js +189 -0
- package/dist/kit-files.d.ts +8 -0
- package/dist/kit-files.js +117 -0
- package/dist/kit-model-keys.d.ts +8 -0
- package/dist/kit-model-keys.js +86 -0
- package/dist/kit-threads.d.ts +3 -0
- package/dist/kit-threads.js +92 -0
- package/dist/kit-tools.d.ts +21 -0
- package/dist/kit-tools.js +47 -0
- package/dist/kit.d.ts +130 -0
- package/dist/kit.js +155 -0
- package/dist/mcp-server.d.ts +27 -0
- package/dist/mcp-server.js +166 -0
- package/dist/next.d.ts +24 -0
- package/dist/next.js +6 -0
- package/dist/ol-signed.d.ts +82 -0
- package/dist/ol-signed.js +115 -0
- package/dist/react/add-server.d.ts +90 -0
- package/dist/react/add-server.js +183 -0
- package/dist/react/agent-chat.d.ts +925 -0
- package/dist/react/agent-chat.js +1917 -0
- package/dist/react/agent-editor.d.ts +133 -0
- package/dist/react/agent-editor.js +222 -0
- package/dist/react/agent-kit.d.ts +160 -0
- package/dist/react/agent-kit.js +279 -0
- package/dist/react/agent-list.d.ts +247 -0
- package/dist/react/agent-list.js +248 -0
- package/dist/react/approval-card.d.ts +272 -0
- package/dist/react/approval-card.js +372 -0
- package/dist/react/artifact-card.d.ts +38 -0
- package/dist/react/artifact-card.js +39 -0
- package/dist/react/avatar.d.ts +21 -0
- package/dist/react/avatar.js +33 -0
- package/dist/react/card-ledger.d.ts +30 -0
- package/dist/react/card-ledger.js +49 -0
- package/dist/react/chat-timing.d.ts +121 -0
- package/dist/react/chat-timing.js +229 -0
- package/dist/react/computer-view.d.ts +309 -0
- package/dist/react/computer-view.js +543 -0
- package/dist/react/computer-viewer.d.ts +175 -0
- package/dist/react/computer-viewer.js +555 -0
- package/dist/react/computer-wire.d.ts +178 -0
- package/dist/react/computer-wire.js +244 -0
- package/dist/react/connect-button.d.ts +145 -0
- package/dist/react/connect-button.js +212 -0
- package/dist/react/connection-request.d.ts +16 -0
- package/dist/react/connection-request.js +18 -0
- package/dist/react/connections-list.d.ts +90 -0
- package/dist/react/connections-list.js +76 -0
- package/dist/react/errors.d.ts +250 -0
- package/dist/react/errors.js +146 -0
- package/dist/react/files.d.ts +41 -0
- package/dist/react/files.js +78 -0
- package/dist/react/index.d.ts +35 -0
- package/dist/react/index.js +26 -0
- package/dist/react/limit-words.d.ts +80 -0
- package/dist/react/limit-words.js +53 -0
- package/dist/react/markdown.d.ts +42 -0
- package/dist/react/markdown.js +56 -0
- package/dist/react/md-parse.d.ts +106 -0
- package/dist/react/md-parse.js +638 -0
- package/dist/react/model-keys-card.d.ts +94 -0
- package/dist/react/model-keys-card.js +123 -0
- package/dist/react/reload.d.ts +211 -0
- package/dist/react/reload.js +339 -0
- package/dist/react/reveal.d.ts +17 -0
- package/dist/react/reveal.js +22 -0
- package/dist/react/schedule-editor.d.ts +107 -0
- package/dist/react/schedule-editor.js +172 -0
- package/dist/react/schedule-time.d.ts +66 -0
- package/dist/react/schedule-time.js +90 -0
- package/dist/react/styles.css +1274 -0
- package/dist/react/transport.d.ts +49 -0
- package/dist/react/transport.js +380 -0
- package/dist/react/use-connections.d.ts +155 -0
- package/dist/react/use-connections.js +231 -0
- package/dist/react/use-model-keys.d.ts +47 -0
- package/dist/react/use-model-keys.js +57 -0
- package/dist/react/use-threads.d.ts +63 -0
- package/dist/react/use-threads.js +73 -0
- package/dist/react/vault-form.d.ts +92 -0
- package/dist/react/vault-form.js +151 -0
- package/dist/schema.d.ts +47 -0
- package/dist/schema.js +16 -0
- package/dist/secrets.d.ts +15 -0
- package/dist/secrets.js +18 -0
- package/dist/stream.d.ts +129 -0
- package/dist/stream.js +192 -0
- package/dist/testing.d.ts +33 -0
- package/dist/testing.js +40 -0
- package/dist/webhooks.d.ts +31 -0
- package/dist/webhooks.js +72 -0
- package/package.json +85 -3
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
|
4
|
+
import { DEFAULT_KIT_BASE, DEFAULT_MODEL_TIER_LABELS, kitRequest, newIdempotencyKey, useHears } from "./agent-kit.js";
|
|
5
|
+
import { Avatar } from "./avatar.js";
|
|
6
|
+
import { useNoteInView } from "./reveal.js";
|
|
7
|
+
export const DEFAULT_AGENT_LIST_LABELS = {
|
|
8
|
+
title: "Agents",
|
|
9
|
+
newAgent: "New agent",
|
|
10
|
+
unseen: "{count} unread",
|
|
11
|
+
waiting: "waiting for your OK",
|
|
12
|
+
working: "working",
|
|
13
|
+
paused: "paused",
|
|
14
|
+
workingMark: "Working…",
|
|
15
|
+
waitingMark: "Needs you",
|
|
16
|
+
pausedMark: "Paused",
|
|
17
|
+
loading: "Loading your agents…",
|
|
18
|
+
empty: "No agents yet.",
|
|
19
|
+
loadFailed: "Your agents didn't load.",
|
|
20
|
+
retry: "Try again",
|
|
21
|
+
more: "Show more agents",
|
|
22
|
+
moreFailed: "More agents didn't load.",
|
|
23
|
+
openFailed: "The conversation with {name} didn't open. Select it to try again.",
|
|
24
|
+
openPaused: "{name} is paused, so it can't start a conversation until it's resumed.",
|
|
25
|
+
models: DEFAULT_MODEL_TIER_LABELS,
|
|
26
|
+
modelAuto: "Auto",
|
|
27
|
+
};
|
|
28
|
+
export function unseenBadge(n) {
|
|
29
|
+
if (!Number.isFinite(n) || n <= 0)
|
|
30
|
+
return null;
|
|
31
|
+
return n >= 100 ? "99+" : String(Math.floor(n));
|
|
32
|
+
}
|
|
33
|
+
export function mergeAgentPage(shown, page) {
|
|
34
|
+
const fresh = new Map(page.map((a) => [a.agent, a]));
|
|
35
|
+
const kept = shown.map((a) => fresh.get(a.agent) ?? a);
|
|
36
|
+
const have = new Set(shown.map((a) => a.agent));
|
|
37
|
+
return [...kept, ...page.filter((a) => !have.has(a.agent))];
|
|
38
|
+
}
|
|
39
|
+
export function refreshedAgents(shown, page, pageSize) {
|
|
40
|
+
if (shown === null || shown.length <= pageSize)
|
|
41
|
+
return [...page];
|
|
42
|
+
return mergeAgentPage(page, shown.slice(pageSize));
|
|
43
|
+
}
|
|
44
|
+
export function agentsAfterNews(shown, news) {
|
|
45
|
+
if (!shown || news.removed === null || !shown.some((a) => a.agent === news.removed))
|
|
46
|
+
return shown;
|
|
47
|
+
return shown.filter((a) => a.agent !== news.removed);
|
|
48
|
+
}
|
|
49
|
+
export function withSeen(shown, seen) {
|
|
50
|
+
if (!shown.some((a) => a.ongoing_thread === seen.thread && a.unseen !== seen.unseen))
|
|
51
|
+
return shown;
|
|
52
|
+
return shown.map((a) => (a.ongoing_thread === seen.thread ? { ...a, unseen: seen.unseen } : a));
|
|
53
|
+
}
|
|
54
|
+
export function withOpened(shown, agent, thread) {
|
|
55
|
+
return shown.map((a) => (a.agent === agent ? { ...a, ongoing_thread: thread } : a));
|
|
56
|
+
}
|
|
57
|
+
export function agentRowName(a, l, open, model = null) {
|
|
58
|
+
const badge = open ? null : unseenBadge(a.unseen);
|
|
59
|
+
return [a.name, ...(model ? [model] : []), ...(badge ? [l.unseen.replace("{count}", badge)] : []), ...(a.waiting > 0 ? [l.waiting] : []), ...(a.working ? [l.working] : []), ...(a.status === "paused" ? [l.paused] : [])].join(", ");
|
|
60
|
+
}
|
|
61
|
+
export function openFailedText(err, l, a) {
|
|
62
|
+
return (err?.code === "agent_paused" ? l.openPaused : l.openFailed).replaceAll("{name}", a.name);
|
|
63
|
+
}
|
|
64
|
+
export function cannotOpen(a) {
|
|
65
|
+
return a.status === "paused" && a.ongoing_thread === null;
|
|
66
|
+
}
|
|
67
|
+
const seenAnswers = typeof EventTarget === "function" ? new EventTarget() : null;
|
|
68
|
+
export async function markSeen(thread, message, opts = {}) {
|
|
69
|
+
const answer = await kitRequest(`/threads/${encodeURIComponent(thread)}/seen`, { ...opts, method: "POST", body: { message } });
|
|
70
|
+
seenAnswers?.dispatchEvent(new CustomEvent("seen", { detail: { thread: answer.thread, unseen: answer.unseen } }));
|
|
71
|
+
return answer;
|
|
72
|
+
}
|
|
73
|
+
const LOOK_EVERY_MS = 30_000;
|
|
74
|
+
export function useAgentList(opts = {}) {
|
|
75
|
+
const seed = opts.initial ?? null;
|
|
76
|
+
const [agents, setAgents] = useState(() => (seed ? [...seed.data] : null));
|
|
77
|
+
const [hasMore, setHasMore] = useState(() => seed?.has_more ?? false);
|
|
78
|
+
const [error, setError] = useState(null);
|
|
79
|
+
const [loading, setLoading] = useState(opts.enabled !== false && !seed);
|
|
80
|
+
const optsRef = useRef(opts);
|
|
81
|
+
optsRef.current = opts;
|
|
82
|
+
const key = opts.enabled === false ? null : `${opts.api ?? DEFAULT_KIT_BASE}|${opts.pageSize ?? 100}`;
|
|
83
|
+
const current = useRef(key);
|
|
84
|
+
const shownFor = useRef(seed ? key : undefined);
|
|
85
|
+
const agentsRef = useRef(agents);
|
|
86
|
+
agentsRef.current = agents;
|
|
87
|
+
const read = useCallback(async (after) => {
|
|
88
|
+
const o = optsRef.current;
|
|
89
|
+
const k = current.current;
|
|
90
|
+
const q = new URLSearchParams({ limit: String(o.pageSize ?? 100), ...(after ? { starting_after: after } : {}) });
|
|
91
|
+
setLoading(true);
|
|
92
|
+
try {
|
|
93
|
+
const page = await kitRequest(`/agents/summary?${q.toString()}`, o);
|
|
94
|
+
if (current.current !== k)
|
|
95
|
+
return false;
|
|
96
|
+
const size = o.pageSize ?? 100;
|
|
97
|
+
setAgents((shown) => (after === null ? refreshedAgents(shown, page.data, size) : mergeAgentPage(shown ?? [], page.data)));
|
|
98
|
+
setHasMore((had) => (after !== null || (agentsRef.current?.length ?? 0) <= size ? page.has_more : had));
|
|
99
|
+
setError(null);
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
if (current.current !== k)
|
|
104
|
+
return false;
|
|
105
|
+
setError(err);
|
|
106
|
+
o.onError?.(err);
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
if (current.current === k)
|
|
111
|
+
setLoading(false);
|
|
112
|
+
}
|
|
113
|
+
}, []);
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
current.current = key;
|
|
116
|
+
if (shownFor.current === key)
|
|
117
|
+
return;
|
|
118
|
+
shownFor.current = key;
|
|
119
|
+
setAgents(null);
|
|
120
|
+
setHasMore(false);
|
|
121
|
+
setError(null);
|
|
122
|
+
if (key !== null)
|
|
123
|
+
void read(null);
|
|
124
|
+
else
|
|
125
|
+
setLoading(false);
|
|
126
|
+
}, [key, read]);
|
|
127
|
+
const every = opts.lookEveryMs ?? LOOK_EVERY_MS;
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
if (key === null || typeof document === "undefined")
|
|
130
|
+
return;
|
|
131
|
+
const visible = () => document.visibilityState === "visible";
|
|
132
|
+
const again = () => {
|
|
133
|
+
if (visible())
|
|
134
|
+
void read(null);
|
|
135
|
+
};
|
|
136
|
+
const timer = every > 0 ? setInterval(again, every) : null;
|
|
137
|
+
document.addEventListener("visibilitychange", again);
|
|
138
|
+
return () => {
|
|
139
|
+
if (timer !== null)
|
|
140
|
+
clearInterval(timer);
|
|
141
|
+
document.removeEventListener("visibilitychange", again);
|
|
142
|
+
};
|
|
143
|
+
}, [key, every, read]);
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
if (!seenAnswers)
|
|
146
|
+
return;
|
|
147
|
+
const heard = (e) => {
|
|
148
|
+
const d = e.detail;
|
|
149
|
+
setAgents((shown) => (shown ? withSeen(shown, d) : shown));
|
|
150
|
+
};
|
|
151
|
+
seenAnswers.addEventListener("seen", heard);
|
|
152
|
+
return () => seenAnswers.removeEventListener("seen", heard);
|
|
153
|
+
}, []);
|
|
154
|
+
const self = useId();
|
|
155
|
+
const agentsChanged = useCallback((news) => {
|
|
156
|
+
setAgents((shown) => agentsAfterNews(shown, news));
|
|
157
|
+
if (current.current !== null)
|
|
158
|
+
void read(null);
|
|
159
|
+
}, [read]);
|
|
160
|
+
useHears("agents", self, agentsChanged);
|
|
161
|
+
return {
|
|
162
|
+
agents,
|
|
163
|
+
hasMore,
|
|
164
|
+
error,
|
|
165
|
+
loading,
|
|
166
|
+
refresh: () => read(null),
|
|
167
|
+
loadMore: async () => {
|
|
168
|
+
const last = agents?.at(-1);
|
|
169
|
+
if (!hasMore || !last || loading)
|
|
170
|
+
return true;
|
|
171
|
+
return read(last.agent);
|
|
172
|
+
},
|
|
173
|
+
open: async (agent) => {
|
|
174
|
+
const t = await kitRequest("/threads", { ...optsRef.current, method: "POST", body: { agent, ongoing: true }, idempotencyKey: newIdempotencyKey() });
|
|
175
|
+
setAgents((shown) => (shown ? withOpened(shown, agent, t.id) : shown));
|
|
176
|
+
return t;
|
|
177
|
+
},
|
|
178
|
+
markSeen: (thread, message) => markSeen(thread, message, optsRef.current),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
const ROW_KEYS = new Set(["ArrowDown", "ArrowUp", "Home", "End"]);
|
|
182
|
+
export function rowAfterKey(key, at, count) {
|
|
183
|
+
if (!ROW_KEYS.has(key) || at < 0 || count === 0)
|
|
184
|
+
return null;
|
|
185
|
+
return key === "Home" ? 0 : key === "End" ? count - 1 : key === "ArrowDown" ? Math.min(at + 1, count - 1) : Math.max(at - 1, 0);
|
|
186
|
+
}
|
|
187
|
+
export function AgentList(props) {
|
|
188
|
+
const l = { ...DEFAULT_AGENT_LIST_LABELS, ...props.labels, models: { ...DEFAULT_AGENT_LIST_LABELS.models, ...props.labels?.models } };
|
|
189
|
+
const { list } = props;
|
|
190
|
+
const Link = props.linkAs ?? "a";
|
|
191
|
+
const tiers = new Map((props.models ?? []).map((m) => [m.id, m.model.mode === "auto" ? "auto" : m.model.tier]));
|
|
192
|
+
const modelOf = (agent) => {
|
|
193
|
+
const t = tiers.get(agent);
|
|
194
|
+
if (t === "auto")
|
|
195
|
+
return l.modelAuto;
|
|
196
|
+
return t ? (l.models[t] ?? null) : null;
|
|
197
|
+
};
|
|
198
|
+
const [opening, setOpening] = useState(null);
|
|
199
|
+
const [failed, setFailed] = useState(null);
|
|
200
|
+
const [moreFailed, setMoreFailed] = useState(false);
|
|
201
|
+
const failedInView = useNoteInView(failed);
|
|
202
|
+
const moreFailedInView = useNoteInView();
|
|
203
|
+
const more = async () => {
|
|
204
|
+
setMoreFailed(false);
|
|
205
|
+
setMoreFailed(!(await list.loadMore()));
|
|
206
|
+
};
|
|
207
|
+
const select = async (a) => {
|
|
208
|
+
if (opening !== null)
|
|
209
|
+
return;
|
|
210
|
+
if (cannotOpen(a))
|
|
211
|
+
return setFailed({ agent: a.agent, text: openFailedText({ code: "agent_paused" }, l, a) });
|
|
212
|
+
setOpening(a.agent);
|
|
213
|
+
setFailed(null);
|
|
214
|
+
try {
|
|
215
|
+
const t = await list.open(a.agent);
|
|
216
|
+
props.onOpen?.(a.agent, t);
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
setFailed({ agent: a.agent, text: openFailedText(err, l, a) });
|
|
220
|
+
}
|
|
221
|
+
finally {
|
|
222
|
+
setOpening(null);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
const onKeyDown = (e) => {
|
|
226
|
+
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)
|
|
227
|
+
return;
|
|
228
|
+
const rows = Array.from(e.currentTarget.querySelectorAll("[data-ol-agent-list-row]"));
|
|
229
|
+
const next = rowAfterKey(e.key, rows.indexOf(e.target), rows.length);
|
|
230
|
+
if (next === null)
|
|
231
|
+
return;
|
|
232
|
+
e.preventDefault();
|
|
233
|
+
rows[next].focus();
|
|
234
|
+
};
|
|
235
|
+
const last = props.lastRow ?? null;
|
|
236
|
+
const agents = list.agents ?? [];
|
|
237
|
+
return (_jsxs("nav", { "data-ol-agent-list": true, "aria-label": l.title, className: props.className, children: [props.header ? _jsx("div", { "data-ol-agent-list-header": true, children: props.header }) : null, list.agents === null ? (list.error && !list.loading ? (_jsxs("p", { "data-ol-agent-list-failed": true, role: "status", children: [l.loadFailed, " ", _jsx("button", { type: "button", "data-ol-agent-list-retry": true, onClick: () => void list.refresh(), children: l.retry })] })) : (_jsx("p", { "data-ol-agent-list-loading": true, role: "status", children: l.loading }))) : list.agents.length === 0 ? (_jsx("p", { "data-ol-agent-list-empty": true, children: l.empty })) : null, agents.length > 0 || last ? (_jsxs("ul", { onKeyDown: onKeyDown, children: [agents.map((a) => {
|
|
238
|
+
const open = props.open === a.agent;
|
|
239
|
+
const count = props.unseen ? props.unseen(a) : open ? 0 : a.unseen;
|
|
240
|
+
const badge = unseenBadge(count);
|
|
241
|
+
const model = modelOf(a.agent);
|
|
242
|
+
const href = props.rowHref?.(a) ?? null;
|
|
243
|
+
const name = (_jsx("span", { "data-ol-agent-name": true, title: a.name, children: a.name }));
|
|
244
|
+
const inside = (_jsxs(_Fragment, { children: [_jsx(Avatar, { agent: a, name: a.name, draw: props.avatar }), model ? (_jsxs("span", { "data-ol-agent-text": true, children: [name, _jsx("span", { "data-ol-agent-preset": true, "aria-hidden": "true", children: model })] })) : (name), a.working ? (_jsx("span", { "data-ol-agent-working": true, "aria-hidden": "true", children: l.workingMark })) : null, a.waiting > 0 ? (_jsx("span", { "data-ol-agent-waiting": true, "aria-hidden": "true", children: l.waitingMark })) : null, a.status === "paused" ? (_jsx("span", { "data-ol-agent-paused": true, "aria-hidden": "true", children: l.pausedMark })) : null, badge ? (_jsx("span", { "data-ol-agent-unseen": true, "aria-hidden": "true", children: badge })) : null] }));
|
|
245
|
+
const row = { "data-ol-agent": a.agent, "data-ol-agent-status": a.status, "data-ol-agent-list-row": "", "aria-current": open ? "page" : undefined, "aria-label": agentRowName({ ...a, unseen: count }, l, false, model) };
|
|
246
|
+
return (_jsxs("li", { children: [href !== null ? (_jsx(Link, { ...row, href: href, children: inside })) : (_jsx("button", { type: "button", ...row, "aria-busy": opening === a.agent, onClick: () => void select(a), children: inside })), failed?.agent === a.agent ? (_jsx("p", { "data-ol-agent-open-failed": true, role: "status", ref: failedInView, children: failed.text })) : null] }, a.agent));
|
|
247
|
+
}), moreFailed ? (_jsx("li", { children: _jsxs("p", { "data-ol-agent-list-more-failed": true, role: "status", ref: moreFailedInView, children: [l.moreFailed, " ", _jsx("button", { type: "button", "data-ol-agent-list-retry": true, "data-ol-agent-list-row": "", onClick: () => void more(), children: l.retry })] }) })) : list.hasMore ? (_jsx("li", { children: _jsx("button", { type: "button", "data-ol-agent-list-more": true, "data-ol-agent-list-row": "", onClick: () => void more(), children: l.more }) })) : null, last ? (_jsx("li", { "data-ol-agent-list-last-row": true, children: last.href !== undefined ? (_jsxs(Link, { "data-ol-agent-list-last": true, "data-ol-agent-list-row": "", href: last.href, ref: last.ref, children: [last.icon ? _jsx("span", { "data-ol-agent-list-icon": true, "aria-hidden": "true", children: last.icon }) : null, _jsx("span", { children: last.label })] })) : (_jsxs("button", { type: "button", "data-ol-agent-list-last": true, "data-ol-agent-list-row": "", ref: last.ref, "aria-haspopup": last.opens, onClick: last.onSelect, children: [last.icon ? _jsx("span", { "data-ol-agent-list-icon": true, "aria-hidden": "true", children: last.icon }) : null, _jsx("span", { children: last.label })] })) })) : null] })) : null, props.onNew ? (_jsx("button", { type: "button", "data-ol-agent-new": true, onClick: props.onNew, children: l.newAgent })) : null] }));
|
|
248
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The approval card: `<AgentChat>` draws it in place of a tool call that needed a person's approval (a tool part
|
|
3
|
+
* that names its `approval: "apr_…"`), held or decided: A DECIDED CARD STAYS A CARD. After a reload it is drawn in
|
|
4
|
+
* place, as decided: its title, its facts behind Details, and "Approved." or "Rejected." in place of the buttons.
|
|
5
|
+
*
|
|
6
|
+
* It reads the approval through the kit's route (`GET {basePath}/approvals/{apr}`), as the person your
|
|
7
|
+
* resolve() answered. It shows what the agent wants to do in the platform's words (the approval's `title` and
|
|
8
|
+
* `fields`), with Approve and Reject. SIMPLE BY DEFAULT: the sentence, the facts the approval puts up front, and
|
|
9
|
+
* "Details" for the rest; `fields="all"` shows every fact. Up front are the facts the approval does not mark
|
|
10
|
+
* `detail` (a tool's `approvalFields` names them); an approval with no marks shows its first two. A decision posts to `POST {basePath}/approvals/{apr}/decide` with the
|
|
11
|
+
* `action_hash` the card was drawn from, so a request that changed since is refused and read again. The
|
|
12
|
+
* platform decides who may decide: an owner or admin, and a member for what their own conversation asked for
|
|
13
|
+
* (unless the template keeps the tool's approvals for admins). The kit's read says whether this person may
|
|
14
|
+
* (`can_decide`): one who may not sees one line in place of the buttons, "Waiting for an admin to decide this.", at
|
|
15
|
+
* once and after a reload; so does one the platform refuses when they try. A read that fails is a short error with
|
|
16
|
+
* Retry, never the waiting line.
|
|
17
|
+
*
|
|
18
|
+
* UNSTYLED, like `<AgentChat>`: `data-ol-approval-*` hooks, every string a label.
|
|
19
|
+
*/
|
|
20
|
+
import { type Ref } from "react";
|
|
21
|
+
import { type AgentChatLabels } from "./errors.ts";
|
|
22
|
+
import { type KitLimit } from "./limit-words.ts";
|
|
23
|
+
/** The kit's approval answer, as the card reads it. */
|
|
24
|
+
export interface ApprovalCardData {
|
|
25
|
+
id: string;
|
|
26
|
+
status: "pending" | "approved" | "rejected" | "expired";
|
|
27
|
+
title: string | null;
|
|
28
|
+
/**
|
|
29
|
+
* The approval's facts, in its order. `detail: true`: the approval puts this one behind the card's Details.
|
|
30
|
+
* `truncated: true`: the value is its first 20,000 characters and an ellipsis; Approve allows the whole of it.
|
|
31
|
+
* `from_page: true`: a web page wrote this value (a held browser act's control, its containers, the page's address;
|
|
32
|
+
* the text the agent will type is its own, an ordinary fact). The platform sends the mark; the card never infers
|
|
33
|
+
* it. Drawn in quotes and read as "The page's words", so a page can never pass for the card's own words.
|
|
34
|
+
*/
|
|
35
|
+
fields: Array<{
|
|
36
|
+
label: string;
|
|
37
|
+
value: string;
|
|
38
|
+
detail?: true;
|
|
39
|
+
truncated?: true;
|
|
40
|
+
from_page?: true;
|
|
41
|
+
}>;
|
|
42
|
+
action_hash: string | null;
|
|
43
|
+
/** Whether the person reading may decide it; null when the kit did not say (a decision's answer, an older kit). */
|
|
44
|
+
can_decide: boolean | null;
|
|
45
|
+
/**
|
|
46
|
+
* A browser act's card: the browser session (`cps_…`) the act would run in, the id on that session's
|
|
47
|
+
* `data-computer` part. While a view open here holds control of it, Approve is held back (`heldSessions`).
|
|
48
|
+
*/
|
|
49
|
+
computer_session?: string;
|
|
50
|
+
/**
|
|
51
|
+
* On a decision's answer only: it was taken, and no run follows it now (the workspace cannot run, or the agent is
|
|
52
|
+
* paused). The refusal a send refused now carries: its code, the person's sentence, and on `cap_reached` the limit.
|
|
53
|
+
*/
|
|
54
|
+
run_refused?: ApprovalRunRefused;
|
|
55
|
+
/**
|
|
56
|
+
* On an approved card: what came of the approved action. `outcome` is null while it waits or runs; `message` is the
|
|
57
|
+
* platform's sentence for the person when it did not succeed. Absent from a route that does not send it.
|
|
58
|
+
*/
|
|
59
|
+
action?: ApprovalAction | null;
|
|
60
|
+
}
|
|
61
|
+
/** What came of an approved action, as the kit's route answers it. */
|
|
62
|
+
export interface ApprovalAction {
|
|
63
|
+
status: string;
|
|
64
|
+
outcome: "succeeded" | "failed" | "refused" | "unknown" | null;
|
|
65
|
+
message: string | null;
|
|
66
|
+
}
|
|
67
|
+
/** Why no run follows a decision (`onDecided`'s `runRefused`): the refusal a send refused now would get. */
|
|
68
|
+
export interface ApprovalRunRefused {
|
|
69
|
+
code: string;
|
|
70
|
+
message: string;
|
|
71
|
+
limit: KitLimit | null;
|
|
72
|
+
}
|
|
73
|
+
/** The kit's `GET {basePath}/approvals/{apr}` answer (or a decision's), or null when it is not one. */
|
|
74
|
+
export declare function approvalCardOf(body: unknown): ApprovalCardData | null;
|
|
75
|
+
/** Read the card through the kit's route. Never throws: a refusal, a network error or another answer is null. */
|
|
76
|
+
export declare function readApproval(opts: {
|
|
77
|
+
base: string;
|
|
78
|
+
id: string;
|
|
79
|
+
fetch: typeof fetch;
|
|
80
|
+
}): Promise<ApprovalCardData | null>;
|
|
81
|
+
/** A decision's answer: the decided card, or the kit's error code. */
|
|
82
|
+
/** `said`: a refusal's own sentence for the person (see `refusalSaid`), when it gave one. */
|
|
83
|
+
export type DecideResult = {
|
|
84
|
+
ok: true;
|
|
85
|
+
card: ApprovalCardData;
|
|
86
|
+
} | {
|
|
87
|
+
ok: false;
|
|
88
|
+
code: string;
|
|
89
|
+
said?: string;
|
|
90
|
+
};
|
|
91
|
+
/** Approve or reject through the kit's route. Never throws: a failed request is `{ok: false, code}`. */
|
|
92
|
+
export declare function decideApproval(opts: {
|
|
93
|
+
base: string;
|
|
94
|
+
id: string;
|
|
95
|
+
decision: "approve" | "reject";
|
|
96
|
+
actionHash: string | null;
|
|
97
|
+
fetch: typeof fetch;
|
|
98
|
+
}): Promise<DecideResult>;
|
|
99
|
+
/** What a refused decision leaves on the card. A person who may not decide (`insufficient_role`) gets no
|
|
100
|
+
* buttons, one line saying an admin will; a changed request a notice; one decided or expired meanwhile
|
|
101
|
+
* is read again; any other refusal its own sentence (`said`, from the server: a host's plan_required), else the
|
|
102
|
+
* generic notice. The buttons stay for all but insufficient_role. */
|
|
103
|
+
export declare function afterRefusal(code: string, labels: Pick<ApprovalLabels, "approvalChanged" | "generic">, said?: string): {
|
|
104
|
+
notice: string | null;
|
|
105
|
+
waiting: boolean;
|
|
106
|
+
readAgain: boolean;
|
|
107
|
+
};
|
|
108
|
+
export type ApprovalLabels = Pick<AgentChatLabels, "approve" | "reject" | "approved" | "rejected" | "wasApproved" | "wasRejected" | "approving" | "rejecting" | "actionFailed" | "actionFailedWith" | "approvalExpired" | "approvalChanged" | "approvalNotAllowed" | "approvalUnavailable" | "retry" | "generic" | "details" | "hideDetails" | "showAll" | "showLess" | "approvalValueCut" | "pageWords" | "approveHeldBack">;
|
|
109
|
+
/**
|
|
110
|
+
* Approve is held back: the card is still open, and a view here holds control of the browser its act would run in.
|
|
111
|
+
* Approving then would use the approval up and the act would not run (the browser refuses the agent while a person
|
|
112
|
+
* holds it). Pure.
|
|
113
|
+
*/
|
|
114
|
+
export declare function heldBackFor(card: Pick<ApprovalCardData, "status" | "computer_session">, held: ReadonlySet<string> | undefined): boolean;
|
|
115
|
+
/** A value is clamped to this many lines, with "Show all", when it may run longer. */
|
|
116
|
+
export declare const VALUE_LINES = 6;
|
|
117
|
+
/**
|
|
118
|
+
* Whether a fact's value may run past `VALUE_LINES` lines on a phone (about 40 characters a line): then it is
|
|
119
|
+
* clamped, with "Show all". The same answer on the server and in the browser; once drawn, a value that turns out
|
|
120
|
+
* to fit loses its button (`Value` measures it).
|
|
121
|
+
*/
|
|
122
|
+
export declare function mayRunLong(value: string): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* A VALUE LONGER THAN THE CARD SHOWS: the API sends a value over 20,000 characters as its
|
|
125
|
+
* first 20,000 and an ellipsis, marked `truncated`, while Approve allows the whole input. The card says so before its
|
|
126
|
+
* buttons, once per cut fact, wherever the fact is drawn (up front or behind Details).
|
|
127
|
+
*/
|
|
128
|
+
export declare function valueCutText(label: string, value: string, template: string): string;
|
|
129
|
+
/** The card as drawn: a pure view of `card`, for the chat and for tests. */
|
|
130
|
+
/**
|
|
131
|
+
* FOCUS AFTER A DECISION: the button the person pressed is replaced by the outcome line, and focus
|
|
132
|
+
* falls to the page. When it was in the card at the tap (`hadFocus`) and is now nowhere (`active` the page's body, or
|
|
133
|
+
* null), the card takes it, without scrolling (the chat takes its end after a decision). Focus the person moved
|
|
134
|
+
* elsewhere meanwhile is left there. True when the card took it.
|
|
135
|
+
*/
|
|
136
|
+
export declare function focusAfterDecision(card: {
|
|
137
|
+
focus(options: {
|
|
138
|
+
preventScroll: boolean;
|
|
139
|
+
}): void;
|
|
140
|
+
} | null, hadFocus: boolean, active: unknown, body: unknown): boolean;
|
|
141
|
+
export declare function ApprovalCardView(props: {
|
|
142
|
+
card: ApprovalCardData;
|
|
143
|
+
fallbackTitle: string;
|
|
144
|
+
labels: ApprovalLabels;
|
|
145
|
+
busy: boolean; /** Which decision is out while `busy`: its words ("Approving…") stand where the buttons were. */
|
|
146
|
+
deciding?: "approve" | "reject" | null | undefined;
|
|
147
|
+
notice: string | null;
|
|
148
|
+
waiting?: boolean; /** Already decided when first read (a reload): "Approved." or "Rejected.", with nothing about carrying on. */
|
|
149
|
+
earlier?: boolean | undefined; /** Decided here and the chat's carry-on after it is over: "Approved.", as a reload says it. A rejection keeps its sentence. */
|
|
150
|
+
settled?: boolean | undefined; /** "fold" (default): two facts, the rest behind Details. "all": every fact. */
|
|
151
|
+
fields?: "fold" | "all" | undefined; /** The person holds control of the browser this act would run in (`heldBackFor`): Approve is disabled, with `labels.approveHeldBack` as its description. */
|
|
152
|
+
heldBack?: boolean | undefined;
|
|
153
|
+
onDecide: (decision: "approve" | "reject") => void; /** The card's root, for focus after a decision. */
|
|
154
|
+
rootRef?: Ref<HTMLDivElement> | undefined;
|
|
155
|
+
}): import("react").JSX.Element;
|
|
156
|
+
/**
|
|
157
|
+
* Before the card is read: the card's own frame, busy, with the held call's line, so the reply's words never point at a
|
|
158
|
+
* card that is not there yet. Not a tool step: a host's tick for a finished step never lands on it. A short
|
|
159
|
+
* error with Retry if the read failed.
|
|
160
|
+
*/
|
|
161
|
+
export declare function ApprovalReadView(props: {
|
|
162
|
+
failed: boolean;
|
|
163
|
+
fallbackTitle: string;
|
|
164
|
+
loadingTitle?: string | undefined;
|
|
165
|
+
labels: ApprovalLabels;
|
|
166
|
+
onRetry: () => void;
|
|
167
|
+
}): import("react").JSX.Element;
|
|
168
|
+
/**
|
|
169
|
+
* One tap's decision, posted by `post`. `onDeciding`, when given, gets at the tap a promise that resolves true once
|
|
170
|
+
* the platform took it with a run to follow; false when it refused it, or took it with no run to follow (`run_refused`).
|
|
171
|
+
*/
|
|
172
|
+
export declare function sendDecision(decision: "approve" | "reject", post: () => Promise<DecideResult>, onDeciding?: (decision: "approve" | "reject", taken: Promise<boolean>) => void): Promise<DecideResult>;
|
|
173
|
+
/**
|
|
174
|
+
* A card first read already decided says so as a reload does ("Approved."), not "The agent carries on"; unless it
|
|
175
|
+
* was decided in this chat and is only mounted again (it moved, and its sentence went within a second).
|
|
176
|
+
*/
|
|
177
|
+
export declare function readsAsEarlier(status: ApprovalCardData["status"], decidedHere: boolean): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Whether an approved card goes on reading its approval: its action has no outcome yet, and a run follows the decision.
|
|
180
|
+
* A route that sends no `action` is never followed.
|
|
181
|
+
*/
|
|
182
|
+
export declare function followsAction(card: ApprovalCardData): boolean;
|
|
183
|
+
/** How long an approved card waits before each read of its action, the last repeated; and how long it follows at most. */
|
|
184
|
+
export declare const FOLLOW_DELAYS_MS: readonly number[];
|
|
185
|
+
export declare const FOLLOW_FOR_MS: number;
|
|
186
|
+
/**
|
|
187
|
+
* AN APPROVED CARD FOLLOWS ITS ACTION TO ITS OUTCOME: it reads the approval soon after the decision,
|
|
188
|
+
* then less often, until the action has an outcome; for ten minutes at most, after which the chat's looks and a reload
|
|
189
|
+
* still read it. A read that fails is tried again on the same schedule. Nothing is read once disposed.
|
|
190
|
+
*/
|
|
191
|
+
export declare function followAction(env: {
|
|
192
|
+
read: () => Promise<ApprovalCardData | null>;
|
|
193
|
+
onRead: (card: ApprovalCardData) => void;
|
|
194
|
+
}): {
|
|
195
|
+
dispose(): void;
|
|
196
|
+
};
|
|
197
|
+
/** A pending card reads its approval again at most once in this long: a focus that also starts the chat's look is one read. */
|
|
198
|
+
export declare const APPROVAL_REREAD_GAP_MS = 2000;
|
|
199
|
+
/**
|
|
200
|
+
* A PENDING CARD READS AGAIN: decided in another tab or on the console, or expired, it
|
|
201
|
+
* stops offering Approve and Reject. `poke` reads unless a read is out or one began within `gapMs`; once disposed (the
|
|
202
|
+
* card decided, or gone) it reads nothing.
|
|
203
|
+
*/
|
|
204
|
+
export declare function approvalRereads(env: {
|
|
205
|
+
read: () => Promise<unknown>;
|
|
206
|
+
now?: () => number;
|
|
207
|
+
gapMs?: number;
|
|
208
|
+
}): {
|
|
209
|
+
poke(): void;
|
|
210
|
+
dispose(): void;
|
|
211
|
+
};
|
|
212
|
+
type Listens = {
|
|
213
|
+
addEventListener(type: string, f: () => void): void;
|
|
214
|
+
removeEventListener(type: string, f: () => void): void;
|
|
215
|
+
};
|
|
216
|
+
/** The tab coming back: the window's focus, or the page shown again. Returns what removes both. */
|
|
217
|
+
export declare function onTabBack(win: Listens, doc: Listens & {
|
|
218
|
+
visibilityState: DocumentVisibilityState;
|
|
219
|
+
}, poke: () => void): () => void;
|
|
220
|
+
/**
|
|
221
|
+
* What a read again does to a pending card: the card as read, and, once it is decided or expired, a reload's words
|
|
222
|
+
* (`earlier`; null leaves them). Null changes nothing: the read failed, or the card is no longer pending here (its
|
|
223
|
+
* own tap decided it while the read was out).
|
|
224
|
+
*/
|
|
225
|
+
export declare function afterReread(current: ApprovalCardData, read: ApprovalCardData | null, decidedHere: boolean): {
|
|
226
|
+
card: ApprovalCardData;
|
|
227
|
+
earlier: boolean | null;
|
|
228
|
+
} | null;
|
|
229
|
+
/**
|
|
230
|
+
* The card for one held call. Until the approval is read it is the tool line (`fallbackTitle`, "Waiting for
|
|
231
|
+
* approval: …"); if the read fails, an error with Retry. `onDecided` runs after a decision the platform took.
|
|
232
|
+
*/
|
|
233
|
+
/** `<ApprovalCard>`'s props. */
|
|
234
|
+
export interface ApprovalCardProps {
|
|
235
|
+
/** apr_…: the approval to show. */
|
|
236
|
+
id: string;
|
|
237
|
+
/** Your kit route's base path (`createHandler`'s `basePath`). Default `/api/openlegion`. */
|
|
238
|
+
base?: string | undefined;
|
|
239
|
+
/** The line shown while the approval is read (and if it cannot be): what the person is asked, in your words. */
|
|
240
|
+
fallbackTitle: string;
|
|
241
|
+
/** The line while it is read, when not `fallbackTitle`: a decided call's own line, so it never reads "Waiting for approval" after a reload. */
|
|
242
|
+
loadingTitle?: string | undefined;
|
|
243
|
+
/** Your words for the card; any you leave out are the kit's (`DEFAULT_LABELS`). */
|
|
244
|
+
labels?: Partial<ApprovalLabels> | undefined;
|
|
245
|
+
/** "fold" (default): the facts the approval puts up front, the rest behind Details. "all": every fact. */
|
|
246
|
+
fields?: "fold" | "all" | undefined;
|
|
247
|
+
/** The `fetch` its reads and its decision go through (a header of yours on each call). Default the page's. */
|
|
248
|
+
fetch?: typeof fetch;
|
|
249
|
+
/**
|
|
250
|
+
* After a decision the platform took. `runRefused`: it was taken, and no run follows it now (the workspace cannot
|
|
251
|
+
* run, or the agent is paused): the refusal a send refused now gets, to say so. The card itself says only "Approved."
|
|
252
|
+
* or "Rejected. …".
|
|
253
|
+
*/
|
|
254
|
+
onDecided?: (decision: "approve" | "reject", after: {
|
|
255
|
+
runRefused: ApprovalRunRefused | null;
|
|
256
|
+
}) => void;
|
|
257
|
+
/** At the tap, before the platform answers: `taken` resolves true once it took the decision with a run to follow. */
|
|
258
|
+
onDeciding?: (decision: "approve" | "reject", taken: Promise<boolean>) => void;
|
|
259
|
+
/** Decided in this chat (the chat keeps it): mounted again, it still says what came of it, not the reload's words. */
|
|
260
|
+
decidedHere?: boolean | undefined;
|
|
261
|
+
/** The carry-on after this chat's decision is over: "Approved.". */
|
|
262
|
+
settled?: boolean | undefined;
|
|
263
|
+
/** Changes each time the chat looks for what arrived: a pending card reads its approval again. */
|
|
264
|
+
look?: number | undefined;
|
|
265
|
+
/**
|
|
266
|
+
* The browser sessions (`cps_…`) whose control the person holds in a view open beside this card. A browser act's
|
|
267
|
+
* card for one of them holds Approve back until control is given back (`<AgentChat>` passes its own).
|
|
268
|
+
*/
|
|
269
|
+
heldSessions?: ReadonlySet<string> | undefined;
|
|
270
|
+
}
|
|
271
|
+
export declare function ApprovalCard(props: ApprovalCardProps): import("react").JSX.Element;
|
|
272
|
+
export {};
|