@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,279 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
|
3
|
+
export const DEFAULT_KIT_BASE = "/api/openlegion";
|
|
4
|
+
export class AgentKitError extends Error {
|
|
5
|
+
name = "AgentKitError";
|
|
6
|
+
code;
|
|
7
|
+
status;
|
|
8
|
+
type;
|
|
9
|
+
param;
|
|
10
|
+
displayMessage;
|
|
11
|
+
constructor(code, message, o = {}) {
|
|
12
|
+
super(message, o.cause === undefined ? undefined : { cause: o.cause });
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.status = o.status ?? null;
|
|
15
|
+
this.type = o.type ?? null;
|
|
16
|
+
this.param = o.param ?? null;
|
|
17
|
+
this.displayMessage = o.displayMessage ?? null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export async function kitRequest(path, init = {}) {
|
|
21
|
+
const f = init.fetch ?? fetch;
|
|
22
|
+
let res;
|
|
23
|
+
try {
|
|
24
|
+
res = await f(`${(init.api ?? DEFAULT_KIT_BASE).replace(/\/+$/, "")}${path}`, {
|
|
25
|
+
method: init.method ?? "GET",
|
|
26
|
+
headers: {
|
|
27
|
+
accept: "application/json",
|
|
28
|
+
...(init.body !== undefined ? { "content-type": "application/json" } : {}),
|
|
29
|
+
...(init.idempotencyKey ? { "idempotency-key": init.idempotencyKey } : {}),
|
|
30
|
+
},
|
|
31
|
+
...(init.body !== undefined ? { body: JSON.stringify(init.body) } : {}),
|
|
32
|
+
credentials: "same-origin",
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
throw new AgentKitError("network", "The request did not reach the server.", { cause: err });
|
|
37
|
+
}
|
|
38
|
+
const parsed = await res.json().catch(() => null);
|
|
39
|
+
if (res.ok)
|
|
40
|
+
return parsed;
|
|
41
|
+
const e = parsed?.error ?? {};
|
|
42
|
+
const str = (v) => (typeof v === "string" ? v : null);
|
|
43
|
+
const type = str(e["type"]);
|
|
44
|
+
throw new AgentKitError(str(e["code"]) ?? `http_${res.status}`, str(e["message"]) ?? `HTTP ${res.status}`, {
|
|
45
|
+
status: res.status,
|
|
46
|
+
type,
|
|
47
|
+
param: str(e["param"]),
|
|
48
|
+
displayMessage: type === "refusal" ? str(e["message"]) : null,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export const DEFAULT_MODEL_TIER_LABELS = { background: "Light", fast: "Fast", reasoning: "Thorough", frontier: "Most capable" };
|
|
52
|
+
export const DEFAULT_KIT_ERROR_LABELS = {
|
|
53
|
+
notAllowed: "Only an account admin can change this.",
|
|
54
|
+
tooOften: "That runs more often than this assistant may run in a day. Choose fewer times.",
|
|
55
|
+
invalid: "Check the highlighted field and try again.",
|
|
56
|
+
modelNotAllowed: "That choice isn't available to you here. Choose another.",
|
|
57
|
+
notFound: "This isn't here any more. Refresh the page.",
|
|
58
|
+
signIn: "Sign in to make changes.",
|
|
59
|
+
rateLimited: "Too many changes at once. Wait a moment and try again.",
|
|
60
|
+
unavailable: "This can't be changed right now. Try again in a moment.",
|
|
61
|
+
generic: "Something went wrong. Please try again.",
|
|
62
|
+
};
|
|
63
|
+
export function agentKitErrorText(err, labels = {}) {
|
|
64
|
+
const l = { ...DEFAULT_KIT_ERROR_LABELS, ...labels };
|
|
65
|
+
if (!(err instanceof AgentKitError))
|
|
66
|
+
return l.generic;
|
|
67
|
+
if (err.type === "refusal") {
|
|
68
|
+
const text = l.refusals?.[err.code] ?? err.displayMessage;
|
|
69
|
+
if (text)
|
|
70
|
+
return text.slice(0, 500);
|
|
71
|
+
}
|
|
72
|
+
if (err.code === "insufficient_role")
|
|
73
|
+
return l.notAllowed;
|
|
74
|
+
if (err.code === "model_tier_not_allowed" || (err.code === "outside_template_bounds" && (err.param === "model_tier" || err.param === "auto_presets")))
|
|
75
|
+
return l.modelNotAllowed;
|
|
76
|
+
if (err.code === "policy_denied")
|
|
77
|
+
return l.tooOften;
|
|
78
|
+
if (err.status === 401)
|
|
79
|
+
return l.signIn;
|
|
80
|
+
if (err.status === 404)
|
|
81
|
+
return l.notFound;
|
|
82
|
+
if (err.status === 429)
|
|
83
|
+
return l.rateLimited;
|
|
84
|
+
if (err.status === 400)
|
|
85
|
+
return l.invalid;
|
|
86
|
+
if (err.code === "network" || (err.status ?? 0) >= 500)
|
|
87
|
+
return l.unavailable;
|
|
88
|
+
return l.generic;
|
|
89
|
+
}
|
|
90
|
+
export function newIdempotencyKey() {
|
|
91
|
+
return typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : `k${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
|
|
92
|
+
}
|
|
93
|
+
function useLoaded(key, load, onError) {
|
|
94
|
+
const [data, setData] = useState(null);
|
|
95
|
+
const [error, setError] = useState(null);
|
|
96
|
+
const [loading, setLoading] = useState(key !== null);
|
|
97
|
+
const current = useRef(key);
|
|
98
|
+
const loadRef = useRef(load);
|
|
99
|
+
loadRef.current = load;
|
|
100
|
+
const onErrorRef = useRef(onError);
|
|
101
|
+
onErrorRef.current = onError;
|
|
102
|
+
const refresh = useCallback(async () => {
|
|
103
|
+
const k = current.current;
|
|
104
|
+
if (k === null)
|
|
105
|
+
return;
|
|
106
|
+
setLoading(true);
|
|
107
|
+
try {
|
|
108
|
+
const d = await loadRef.current();
|
|
109
|
+
if (current.current === k) {
|
|
110
|
+
setData(d);
|
|
111
|
+
setError(null);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
if (current.current === k)
|
|
116
|
+
setError(err);
|
|
117
|
+
onErrorRef.current?.(err);
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
if (current.current === k)
|
|
121
|
+
setLoading(false);
|
|
122
|
+
}
|
|
123
|
+
}, []);
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
current.current = key;
|
|
126
|
+
setData(null);
|
|
127
|
+
setError(null);
|
|
128
|
+
if (key !== null)
|
|
129
|
+
void refresh();
|
|
130
|
+
else
|
|
131
|
+
setLoading(false);
|
|
132
|
+
}, [key, refresh]);
|
|
133
|
+
return { data, error, loading, refresh, set: (f) => setData((d) => f(d)) };
|
|
134
|
+
}
|
|
135
|
+
function agentLimitOf(v) {
|
|
136
|
+
const o = v;
|
|
137
|
+
return Number.isInteger(o?.count) && Number.isInteger(o?.max) ? { count: o.count, max: o.max } : null;
|
|
138
|
+
}
|
|
139
|
+
const KIT_CHANGED = "openlegion:kit-changed";
|
|
140
|
+
export function announce(topic, from, news = {}) {
|
|
141
|
+
if (typeof window !== "undefined")
|
|
142
|
+
window.dispatchEvent(new CustomEvent(KIT_CHANGED, { detail: { topic, from, ...news } }));
|
|
143
|
+
}
|
|
144
|
+
export function hearKit(topic, self, heard) {
|
|
145
|
+
if (typeof window === "undefined")
|
|
146
|
+
return () => undefined;
|
|
147
|
+
const on = (e) => {
|
|
148
|
+
const d = e.detail;
|
|
149
|
+
if (d?.topic === topic && d.from !== self)
|
|
150
|
+
void heard({ removed: typeof d.removed === "string" ? d.removed : null });
|
|
151
|
+
};
|
|
152
|
+
window.addEventListener(KIT_CHANGED, on);
|
|
153
|
+
return () => window.removeEventListener(KIT_CHANGED, on);
|
|
154
|
+
}
|
|
155
|
+
export function useHears(topic, self, refresh) {
|
|
156
|
+
useEffect(() => hearKit(topic, self, refresh), [topic, self, refresh]);
|
|
157
|
+
}
|
|
158
|
+
export function useTemplateAgents(opts = {}) {
|
|
159
|
+
const self = useId();
|
|
160
|
+
const r = useLoaded(opts.enabled === false ? null : (opts.api ?? DEFAULT_KIT_BASE), async () => {
|
|
161
|
+
const page = await kitRequest("/template_agents", opts);
|
|
162
|
+
return { templateAgents: page.data, agentLimit: agentLimitOf(page.agent_limit) };
|
|
163
|
+
}, opts.onError);
|
|
164
|
+
useHears("agents", self, r.refresh);
|
|
165
|
+
return {
|
|
166
|
+
templateAgents: r.data?.templateAgents ?? null,
|
|
167
|
+
agentLimit: r.data?.agentLimit ?? null,
|
|
168
|
+
error: r.error,
|
|
169
|
+
loading: r.loading,
|
|
170
|
+
refresh: r.refresh,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const isModelPreset = (v) => {
|
|
174
|
+
const p = v;
|
|
175
|
+
return typeof p?.id === "string" && typeof p.model?.name === "string" && p.model.name !== "" && (p.key === "openlegion" || p.key === "own");
|
|
176
|
+
};
|
|
177
|
+
const presetReads = new WeakMap();
|
|
178
|
+
export function readModelPresets(opts = {}) {
|
|
179
|
+
const f = opts.fetch ?? fetch;
|
|
180
|
+
const base = (opts.api ?? DEFAULT_KIT_BASE).replace(/\/+$/, "");
|
|
181
|
+
let byBase = presetReads.get(f);
|
|
182
|
+
if (!byBase)
|
|
183
|
+
presetReads.set(f, (byBase = new Map()));
|
|
184
|
+
let read = byBase.get(base);
|
|
185
|
+
if (!read) {
|
|
186
|
+
read = kitRequest("/model_presets", { api: base, fetch: f }).then((page) => {
|
|
187
|
+
if (!Array.isArray(page?.data) || !page.data.every(isModelPreset))
|
|
188
|
+
throw new AgentKitError("invalid_answer", "GET /model_presets did not answer a list of model presets.");
|
|
189
|
+
return page.data;
|
|
190
|
+
});
|
|
191
|
+
byBase.set(base, read);
|
|
192
|
+
}
|
|
193
|
+
return read;
|
|
194
|
+
}
|
|
195
|
+
export function useModelPresets(opts = {}) {
|
|
196
|
+
const [presets, setPresets] = useState(null);
|
|
197
|
+
const optsRef = useRef(opts);
|
|
198
|
+
optsRef.current = opts;
|
|
199
|
+
const key = opts.enabled === false ? null : (opts.api ?? DEFAULT_KIT_BASE);
|
|
200
|
+
useEffect(() => {
|
|
201
|
+
setPresets(null);
|
|
202
|
+
if (key === null)
|
|
203
|
+
return;
|
|
204
|
+
let live = true;
|
|
205
|
+
readModelPresets({ api: key, fetch: optsRef.current.fetch }).then((p) => {
|
|
206
|
+
if (live)
|
|
207
|
+
setPresets(p);
|
|
208
|
+
}, (err) => {
|
|
209
|
+
if (live)
|
|
210
|
+
optsRef.current.onError?.(err);
|
|
211
|
+
});
|
|
212
|
+
return () => {
|
|
213
|
+
live = false;
|
|
214
|
+
};
|
|
215
|
+
}, [key]);
|
|
216
|
+
return presets;
|
|
217
|
+
}
|
|
218
|
+
export function useAgents(opts = {}) {
|
|
219
|
+
const self = useId();
|
|
220
|
+
const r = useLoaded(opts.api ?? DEFAULT_KIT_BASE, async () => (await kitRequest("/agents?limit=100", opts)).data, opts.onError);
|
|
221
|
+
useHears("agents", self, r.refresh);
|
|
222
|
+
const upsert = (a) => r.set((list) => (list ? (list.some((x) => x.id === a.id) ? list.map((x) => (x.id === a.id ? a : x)) : [...list, a]) : [a]));
|
|
223
|
+
return {
|
|
224
|
+
agents: r.data,
|
|
225
|
+
error: r.error,
|
|
226
|
+
loading: r.loading,
|
|
227
|
+
refresh: r.refresh,
|
|
228
|
+
create: async (body, idempotencyKey = newIdempotencyKey()) => {
|
|
229
|
+
const a = await kitRequest("/agents", { ...opts, method: "POST", body, idempotencyKey });
|
|
230
|
+
upsert(a);
|
|
231
|
+
announce("agents", self);
|
|
232
|
+
return a;
|
|
233
|
+
},
|
|
234
|
+
update: async (id, body, idempotencyKey = newIdempotencyKey()) => {
|
|
235
|
+
const a = await kitRequest(`/agents/${encodeURIComponent(id)}`, { ...opts, method: "POST", body, idempotencyKey });
|
|
236
|
+
upsert(a);
|
|
237
|
+
return a;
|
|
238
|
+
},
|
|
239
|
+
pause: async (id) => {
|
|
240
|
+
const a = await kitRequest(`/agents/${encodeURIComponent(id)}/pause`, { ...opts, method: "POST" });
|
|
241
|
+
upsert(a);
|
|
242
|
+
return a;
|
|
243
|
+
},
|
|
244
|
+
resume: async (id) => {
|
|
245
|
+
const a = await kitRequest(`/agents/${encodeURIComponent(id)}/resume`, { ...opts, method: "POST" });
|
|
246
|
+
upsert(a);
|
|
247
|
+
return a;
|
|
248
|
+
},
|
|
249
|
+
remove: async (id) => {
|
|
250
|
+
await kitRequest(`/agents/${encodeURIComponent(id)}`, { ...opts, method: "DELETE" });
|
|
251
|
+
r.set((list) => (list ? list.filter((x) => x.id !== id) : list));
|
|
252
|
+
announce("agents", self, { removed: id });
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
export function useSchedules(agentId, opts = {}) {
|
|
257
|
+
const r = useLoaded(agentId === null ? null : `${opts.api ?? DEFAULT_KIT_BASE}|${agentId}`, async () => (await kitRequest(`/schedules?agent=${encodeURIComponent(agentId ?? "")}&limit=100`, opts)).data, opts.onError);
|
|
258
|
+
const upsert = (s) => r.set((list) => {
|
|
259
|
+
const rest = (list ?? []).filter((x) => x.id !== s.id);
|
|
260
|
+
return s.status === "cancelled" ? rest : list?.some((x) => x.id === s.id) ? (list ?? []).map((x) => (x.id === s.id ? s : x)) : [...rest, s];
|
|
261
|
+
});
|
|
262
|
+
const act = async (path, method, body, idempotencyKey) => {
|
|
263
|
+
const s = await kitRequest(path, { ...opts, method, ...(body === undefined ? {} : { body }), ...(idempotencyKey ? { idempotencyKey } : {}) });
|
|
264
|
+
upsert(s);
|
|
265
|
+
return s;
|
|
266
|
+
};
|
|
267
|
+
const one = (id) => `/schedules/${encodeURIComponent(id)}`;
|
|
268
|
+
return {
|
|
269
|
+
schedules: r.data,
|
|
270
|
+
error: r.error,
|
|
271
|
+
loading: r.loading,
|
|
272
|
+
refresh: r.refresh,
|
|
273
|
+
create: (body, idempotencyKey = newIdempotencyKey()) => act("/schedules", "POST", { ...body, agent: agentId }, idempotencyKey),
|
|
274
|
+
update: (id, body, idempotencyKey = newIdempotencyKey()) => act(one(id), "POST", body, idempotencyKey),
|
|
275
|
+
pause: (id) => act(`${one(id)}/pause`, "POST", {}),
|
|
276
|
+
resume: (id) => act(`${one(id)}/resume`, "POST", {}),
|
|
277
|
+
cancel: (id) => act(one(id), "DELETE"),
|
|
278
|
+
};
|
|
279
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE AGENT LIST (one ongoing conversation per agent): your user's agents for a left bar, in one read of the
|
|
3
|
+
* kit's `{basePath}/agents/summary`, as the person your `resolve()` answers. Each agent with one unseen badge, a
|
|
4
|
+
* working mark ("Working…", in words: a dot beside a badge reads as unread), "Needs you" while an approval of it waits
|
|
5
|
+
* for the person (it stays on the open row: seen is not answered), and "Paused" when it is; select opens its one
|
|
6
|
+
* ongoing conversation; "New agent" is yours.
|
|
7
|
+
*
|
|
8
|
+
* const list = useAgentList();
|
|
9
|
+
* <AgentList list={list} open={agentId} onOpen={(agent, thread) => show(agent, thread)} onNew={() => startNew()} />
|
|
10
|
+
* <AgentChat threadId={thread} />
|
|
11
|
+
*
|
|
12
|
+
* - SELECT OPENS THE ONGOING CONVERSATION through `POST {basePath}/threads {agent, ongoing: true}`: 200 when it
|
|
13
|
+
* existed, 201 when this made it. Never a thread id guessed from the list: the API decides which one it is (the
|
|
14
|
+
* agent's home conversation for an owner or admin, a member's newest).
|
|
15
|
+
* - THE BADGE is what the person has not seen in that conversation: nothing at 0, the count to 99, "99+" at 100 (the
|
|
16
|
+
* API's 100 means 100 or more). The conversation open now shows none: the person is looking at it. A host with its
|
|
17
|
+
* own count (news in the agent's other conversations too) passes `unseen`, drawn on the open row as on any other.
|
|
18
|
+
* - SEEN: `markSeen(thread, message)` posts `{basePath}/threads/{thread}/seen` and every list on the page takes the
|
|
19
|
+
* answer's `unseen` at once. A person's own message clears what came before it with no call.
|
|
20
|
+
* - The list is read again every 30 s while the page is visible (`lookEveryMs`), and when the page comes back.
|
|
21
|
+
* - YOUR SERVER'S READ FIRST: an app that read the agents on its server (`ol.agents.summary()`, as the person) passes
|
|
22
|
+
* its rows as `useAgentList({ initial: { data, has_more } })`, and the bar draws them at once, with no loading line.
|
|
23
|
+
* - YOUR BAR AROUND IT: `header` above the list, `lastRow` (your action, the list's last row), `rowHref` (each row
|
|
24
|
+
* your link), `avatar` (your picture before each name; the art is yours). Up, Down, Home and End move between rows.
|
|
25
|
+
*/
|
|
26
|
+
import { type ElementType, type ReactNode, type Ref } from "react";
|
|
27
|
+
import { type KitAgent, type KitNews, type UseAgentKitOptions } from "./agent-kit.ts";
|
|
28
|
+
import type { KitThread } from "./use-threads.ts";
|
|
29
|
+
import { type AvatarFor } from "./avatar.tsx";
|
|
30
|
+
/** One agent as the person's left bar shows it (the API's `agent_summary`). */
|
|
31
|
+
export interface KitAgentSummary {
|
|
32
|
+
object: "agent_summary";
|
|
33
|
+
/** agt_… */
|
|
34
|
+
agent: string;
|
|
35
|
+
name: string;
|
|
36
|
+
status: "active" | "paused";
|
|
37
|
+
/** The person's ongoing conversation with it (thr_…), or null before there is one. */
|
|
38
|
+
ongoing_thread: string | null;
|
|
39
|
+
/** What the person has not seen there. 100 means 100 or more. */
|
|
40
|
+
unseen: number;
|
|
41
|
+
/** Approvals of this agent waiting for this person. 100 means 100 or more. */
|
|
42
|
+
waiting: number;
|
|
43
|
+
/** A run of this agent is answering or queued where this person sees it. */
|
|
44
|
+
working: boolean;
|
|
45
|
+
/** The ongoing conversation's newest message, or null. */
|
|
46
|
+
last_message_at: string | null;
|
|
47
|
+
}
|
|
48
|
+
export interface AgentListLabels {
|
|
49
|
+
/** The list's accessible name. */
|
|
50
|
+
title: string;
|
|
51
|
+
/** Your "New agent" button. */
|
|
52
|
+
newAgent: string;
|
|
53
|
+
/** A row's unseen count, to a screen reader: `{count}` is the badge ("3", "99+"). */
|
|
54
|
+
unseen: string;
|
|
55
|
+
/** An agent waiting on the person (an approval they haven't answered), in its row's name to a screen reader. */
|
|
56
|
+
waiting: string;
|
|
57
|
+
/** A working agent, in its row's name to a screen reader. */
|
|
58
|
+
working: string;
|
|
59
|
+
/** A paused agent, in its row's name to a screen reader. */
|
|
60
|
+
paused: string;
|
|
61
|
+
/** The working mark, as the row shows it. */
|
|
62
|
+
workingMark: string;
|
|
63
|
+
/** The waiting mark, as the row shows it: on the row while the person has an approval of it to answer, open or not. */
|
|
64
|
+
waitingMark: string;
|
|
65
|
+
/** A paused agent, as the row shows it. */
|
|
66
|
+
pausedMark: string;
|
|
67
|
+
loading: string;
|
|
68
|
+
empty: string;
|
|
69
|
+
loadFailed: string;
|
|
70
|
+
retry: string;
|
|
71
|
+
/** Reads the next page (more than 100 agents). */
|
|
72
|
+
more: string;
|
|
73
|
+
/** The next page didn't load, beside `retry`. */
|
|
74
|
+
moreFailed: string;
|
|
75
|
+
/** Select failed: `{name}` is the agent's. */
|
|
76
|
+
openFailed: string;
|
|
77
|
+
/** Select can't open one: the agent is paused and has no conversation yet. `{name}` is the agent's. */
|
|
78
|
+
openPaused: string;
|
|
79
|
+
/** A model preset's name, under the agent's when you pass `models`. The editor's words by default. */
|
|
80
|
+
models: Record<"background" | "fast" | "reasoning" | "frontier", string>;
|
|
81
|
+
/** Under the name of an agent on Auto (`models`), in place of its preset's. */
|
|
82
|
+
modelAuto: string;
|
|
83
|
+
}
|
|
84
|
+
export declare const DEFAULT_AGENT_LIST_LABELS: AgentListLabels;
|
|
85
|
+
/** The badge: null at 0 (none drawn), the count to 99, "99+" at 100 (the API's 100 means 100 or more). */
|
|
86
|
+
export declare function unseenBadge(n: number): string | null;
|
|
87
|
+
/** A next page below what is shown; an agent already shown is updated in place (read again while paging). */
|
|
88
|
+
export declare function mergeAgentPage(shown: readonly KitAgentSummary[], page: readonly KitAgentSummary[]): KitAgentSummary[];
|
|
89
|
+
/**
|
|
90
|
+
* The list read again from the top: the first page in place of the first `pageSize` shown (an agent gone from it is
|
|
91
|
+
* gone), and any later pages the person opened kept below it.
|
|
92
|
+
*/
|
|
93
|
+
export declare function refreshedAgents(shown: readonly KitAgentSummary[] | null, page: readonly KitAgentSummary[], pageSize: number): KitAgentSummary[];
|
|
94
|
+
/**
|
|
95
|
+
* Another kit hook on the page made or removed an assistant (`useAgents`): a removed one leaves the list at once,
|
|
96
|
+
* wherever it is (a later page too, which the read from the top keeps). `shown` itself for any other news.
|
|
97
|
+
*/
|
|
98
|
+
export declare function agentsAfterNews(shown: KitAgentSummary[] | null, news: KitNews): KitAgentSummary[] | null;
|
|
99
|
+
/** What a seen call answered: the agent whose ongoing conversation it is takes its `unseen`. `shown` itself when none is. */
|
|
100
|
+
export declare function withSeen(shown: KitAgentSummary[], seen: {
|
|
101
|
+
thread: string;
|
|
102
|
+
unseen: number;
|
|
103
|
+
}): KitAgentSummary[];
|
|
104
|
+
/** Select opened `thread` as `agent`'s ongoing conversation. */
|
|
105
|
+
export declare function withOpened(shown: KitAgentSummary[], agent: string, thread: string): KitAgentSummary[];
|
|
106
|
+
/**
|
|
107
|
+
* A row's accessible name: the agent's name, its model preset when the row shows one (`model`), then what the badge
|
|
108
|
+
* and marks show ("Ana, Thorough, 3 unread, waiting for your OK, working"). The conversation open now (`open`) counts
|
|
109
|
+
* nothing unseen: the person is looking at it, and no badge is drawn. Waiting stays: seen is not answered.
|
|
110
|
+
*/
|
|
111
|
+
export declare function agentRowName(a: KitAgentSummary, l: AgentListLabels, open: boolean, model?: string | null): string;
|
|
112
|
+
/** What a failed select says, by the agent's name: paused with no conversation yet (`agent_paused`), else how to try again. */
|
|
113
|
+
export declare function openFailedText(err: unknown, l: AgentListLabels, a: Pick<KitAgentSummary, "name">): string;
|
|
114
|
+
/**
|
|
115
|
+
* A paused agent with no conversation yet can't open one (the API refuses to make one: `agent_paused`), so select
|
|
116
|
+
* says so at once and asks nothing. One that has a conversation opens even while paused: opening it is a read.
|
|
117
|
+
*/
|
|
118
|
+
export declare function cannotOpen(a: Pick<KitAgentSummary, "status" | "ongoing_thread">): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* The person has seen `thread` through `message` (msg_…): `POST {basePath}/threads/{thread}/seen`. Every
|
|
121
|
+
* `useAgentList` on the page takes the answer's `unseen` at once. A mark never moves back, so an older message, or
|
|
122
|
+
* the same one twice, is harmless. Answers the API's `thread_seen`; a failure throws an `AgentKitError`.
|
|
123
|
+
*/
|
|
124
|
+
export declare function markSeen(thread: string, message: string, opts?: UseAgentKitOptions): Promise<{
|
|
125
|
+
object: "thread_seen";
|
|
126
|
+
thread: string;
|
|
127
|
+
seen_through: string;
|
|
128
|
+
unseen: number;
|
|
129
|
+
}>;
|
|
130
|
+
export interface UseAgentListOptions extends UseAgentKitOptions {
|
|
131
|
+
/** How many a page reads, 1–100. Default 100. */
|
|
132
|
+
pageSize?: number | undefined;
|
|
133
|
+
/** Read again every this many ms while the page is visible. Default 30 000; 0: only when the page comes back. */
|
|
134
|
+
lookEveryMs?: number | undefined;
|
|
135
|
+
/** false: read nothing (yet). */
|
|
136
|
+
enabled?: boolean | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* The person's agents your server already read (`await ol.agents.summary({ limit })` as this same person, with the
|
|
139
|
+
* same `pageSize`), as `{ data: page.data, has_more: page.has_more }`: a server component hands a client one plain
|
|
140
|
+
* objects only, and the page carries its response. Drawn at once, in your server's HTML and the browser's first
|
|
141
|
+
* paint, so the bar never shows "Loading your agents…" before them. Not read again at mount: the next read is the usual one
|
|
142
|
+
* (`lookEveryMs`, or the page coming back). Taken once, for the list the hook starts with; a later change is ignored.
|
|
143
|
+
*/
|
|
144
|
+
initial?: {
|
|
145
|
+
data: readonly KitAgentSummary[];
|
|
146
|
+
has_more: boolean;
|
|
147
|
+
} | null | undefined;
|
|
148
|
+
}
|
|
149
|
+
export declare function useAgentList(opts?: UseAgentListOptions): {
|
|
150
|
+
/** Oldest agent first, as `GET /agents`; null before the first read. */
|
|
151
|
+
agents: KitAgentSummary[] | null;
|
|
152
|
+
hasMore: boolean;
|
|
153
|
+
error: Error | null;
|
|
154
|
+
loading: boolean;
|
|
155
|
+
/** Read the list again now. */
|
|
156
|
+
refresh: () => Promise<boolean>;
|
|
157
|
+
/** Read the next page (more than `pageSize` agents). False when it didn't load. */
|
|
158
|
+
loadMore: () => Promise<boolean>;
|
|
159
|
+
/**
|
|
160
|
+
* Open `agent`'s ongoing conversation: `POST {basePath}/threads {agent, ongoing: true}` (made when there is none
|
|
161
|
+
* yet). Answers the conversation; pass its id to `<AgentChat threadId>`. A failure throws an `AgentKitError`
|
|
162
|
+
* (`agent_paused`: the agent is paused and has no conversation yet).
|
|
163
|
+
*/
|
|
164
|
+
open: (agent: string) => Promise<KitThread>;
|
|
165
|
+
/** `markSeen` through this list's options. */
|
|
166
|
+
markSeen: (thread: string, message: string) => Promise<{
|
|
167
|
+
object: "thread_seen";
|
|
168
|
+
thread: string;
|
|
169
|
+
seen_through: string;
|
|
170
|
+
unseen: number;
|
|
171
|
+
}>;
|
|
172
|
+
};
|
|
173
|
+
export type AgentListState = ReturnType<typeof useAgentList>;
|
|
174
|
+
/**
|
|
175
|
+
* Your action as the list's LAST ROW ("New agent", "Browse agents"): inside the list, after every agent and after
|
|
176
|
+
* "Show more agents", so it stays last however many pages are read; in the list's arrow-key order (Up, Down, Home and
|
|
177
|
+
* End reach it). Never an agent: no badge, never marked open.
|
|
178
|
+
* - `onSelect`: it opens something of yours (a dialog, a form), so it is a button.
|
|
179
|
+
* - `href`: it goes somewhere, so it is a link (through `linkAs`).
|
|
180
|
+
* - `ref`: the element, to hand the focus back to when what it opened closes. For a dialog of yours: put the focus
|
|
181
|
+
* on this row BEFORE the dialog opens, and the browser gives it back when the dialog closes.
|
|
182
|
+
*/
|
|
183
|
+
export interface AgentListLastRow {
|
|
184
|
+
label: string;
|
|
185
|
+
/** Drawn in the avatar's box before the label; hidden from screen readers (the label says it). */
|
|
186
|
+
icon?: ReactNode;
|
|
187
|
+
onSelect?: () => void;
|
|
188
|
+
href?: string;
|
|
189
|
+
ref?: Ref<HTMLElement>;
|
|
190
|
+
/**
|
|
191
|
+
* What `onSelect` opens, when it is a dialog or a menu: said to a screen reader (`aria-haspopup`). Only you know, so
|
|
192
|
+
* it is never guessed. None on a link.
|
|
193
|
+
*/
|
|
194
|
+
opens?: "dialog" | "menu" | "listbox" | "tree" | "grid" | undefined;
|
|
195
|
+
}
|
|
196
|
+
export interface AgentListProps {
|
|
197
|
+
/** `useAgentList()`'s result: yours, so your page can refresh it or read `waiting`. */
|
|
198
|
+
list: AgentListState;
|
|
199
|
+
/** The agent whose conversation is open now (agt_…): marked, and no badge unless `unseen` gives it one. */
|
|
200
|
+
open?: string | null | undefined;
|
|
201
|
+
/**
|
|
202
|
+
* YOUR COUNT for each row's badge, the open row's too: what is unseen in all of the agent's conversations, say,
|
|
203
|
+
* leaving out the one on screen (yours to leave out). Drawn on the open row exactly as on a closed one; 0 draws none.
|
|
204
|
+
* Absent: the summary's `unseen`, the agent's ongoing conversation, which on the open row is the one on screen, so
|
|
205
|
+
* the open row draws none.
|
|
206
|
+
*/
|
|
207
|
+
unseen?: ((agent: KitAgentSummary) => number) | undefined;
|
|
208
|
+
/**
|
|
209
|
+
* Select opened `agent`'s ongoing conversation: show it (`<AgentChat threadId={thread.id}>`). Called for a row that
|
|
210
|
+
* is a button; a row that is your link (`rowHref`) goes where it says instead.
|
|
211
|
+
*/
|
|
212
|
+
onOpen?: ((agent: string, thread: KitThread) => void) | undefined;
|
|
213
|
+
/**
|
|
214
|
+
* Each agent's row as YOUR link: its address (from `agent.ongoing_thread`, say), so a click is a navigation your app
|
|
215
|
+
* owns. Null for a row that stays a button (one with no conversation yet: select makes it and calls `onOpen`).
|
|
216
|
+
*/
|
|
217
|
+
rowHref?: ((agent: KitAgentSummary) => string | null | undefined) | undefined;
|
|
218
|
+
/** What draws a link (a row's, the last row's): your router's (`Link` from next/link), else a plain `<a>`. */
|
|
219
|
+
linkAs?: ElementType | undefined;
|
|
220
|
+
/** Above the list, inside the bar's landmark but outside the list and its arrow keys: your mark, a name, a link home. */
|
|
221
|
+
header?: ReactNode;
|
|
222
|
+
/** Your action as the list's last row: see `AgentListLastRow`. */
|
|
223
|
+
lastRow?: AgentListLastRow | null | undefined;
|
|
224
|
+
/** "New agent" as a button below the list: your flow. No button without it. (`lastRow` puts an action in the list.) */
|
|
225
|
+
onNew?: (() => void) | undefined;
|
|
226
|
+
/**
|
|
227
|
+
* The picture before each agent's name, yours: `(agent) => <img src={…} alt="" />`, in a fixed box (nothing moves
|
|
228
|
+
* when it loads or fails). Absent: the name's first letter in a circle. Null: none.
|
|
229
|
+
*/
|
|
230
|
+
avatar?: AvatarFor<KitAgentSummary>;
|
|
231
|
+
/**
|
|
232
|
+
* The agents with their model (`useAgents().agents`): each row shows its preset's name under the agent's
|
|
233
|
+
* ("Thorough"). Absent (the default), no row does. An agent not in it shows none.
|
|
234
|
+
*/
|
|
235
|
+
models?: ReadonlyArray<Pick<KitAgent, "id" | "model">> | null | undefined;
|
|
236
|
+
labels?: Partial<AgentListLabels> | undefined;
|
|
237
|
+
className?: string | undefined;
|
|
238
|
+
}
|
|
239
|
+
/** The row a key moves to, from the row at `at` of `count` (no wrap: Home and End are the ends). Null: not ours. */
|
|
240
|
+
export declare function rowAfterKey(key: string, at: number, count: number): number | null;
|
|
241
|
+
/**
|
|
242
|
+
* `<AgentList>`: the person's agents as a nav: each row its avatar, name, one unseen badge, a working mark and a waiting one; the
|
|
243
|
+
* open one marked (`aria-current`). A row is a button that opens the agent's ongoing conversation (`list.open`, then
|
|
244
|
+
* `onOpen`), or your link (`rowHref`). Arrow keys, Home and End move between the rows, your last row included.
|
|
245
|
+
* Styled by the kit's stylesheet; plain buttons and links without it.
|
|
246
|
+
*/
|
|
247
|
+
export declare function AgentList(props: AgentListProps): import("react").JSX.Element;
|