@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.
Files changed (120) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +1189 -2
  3. package/dist/body.d.ts +9 -0
  4. package/dist/body.js +28 -0
  5. package/dist/chat-history.d.ts +53 -0
  6. package/dist/chat-history.js +11 -0
  7. package/dist/client.d.ts +217 -0
  8. package/dist/client.js +367 -0
  9. package/dist/core.d.ts +47 -0
  10. package/dist/core.js +1 -0
  11. package/dist/crypto.d.ts +25 -0
  12. package/dist/crypto.js +81 -0
  13. package/dist/errors.d.ts +111 -0
  14. package/dist/errors.js +134 -0
  15. package/dist/events.d.ts +131 -0
  16. package/dist/events.js +5 -0
  17. package/dist/generated/api.d.ts +5505 -0
  18. package/dist/generated/api.js +446 -0
  19. package/dist/handler.d.ts +201 -0
  20. package/dist/handler.js +682 -0
  21. package/dist/index.d.ts +24 -0
  22. package/dist/index.js +12 -0
  23. package/dist/kit-agents.d.ts +95 -0
  24. package/dist/kit-agents.js +280 -0
  25. package/dist/kit-codes.d.ts +279 -0
  26. package/dist/kit-codes.js +44 -0
  27. package/dist/kit-connections.d.ts +21 -0
  28. package/dist/kit-connections.js +189 -0
  29. package/dist/kit-files.d.ts +8 -0
  30. package/dist/kit-files.js +117 -0
  31. package/dist/kit-model-keys.d.ts +8 -0
  32. package/dist/kit-model-keys.js +86 -0
  33. package/dist/kit-threads.d.ts +3 -0
  34. package/dist/kit-threads.js +92 -0
  35. package/dist/kit-tools.d.ts +21 -0
  36. package/dist/kit-tools.js +47 -0
  37. package/dist/kit.d.ts +130 -0
  38. package/dist/kit.js +155 -0
  39. package/dist/mcp-server.d.ts +27 -0
  40. package/dist/mcp-server.js +166 -0
  41. package/dist/next.d.ts +24 -0
  42. package/dist/next.js +6 -0
  43. package/dist/ol-signed.d.ts +82 -0
  44. package/dist/ol-signed.js +115 -0
  45. package/dist/react/add-server.d.ts +90 -0
  46. package/dist/react/add-server.js +183 -0
  47. package/dist/react/agent-chat.d.ts +925 -0
  48. package/dist/react/agent-chat.js +1917 -0
  49. package/dist/react/agent-editor.d.ts +133 -0
  50. package/dist/react/agent-editor.js +222 -0
  51. package/dist/react/agent-kit.d.ts +160 -0
  52. package/dist/react/agent-kit.js +279 -0
  53. package/dist/react/agent-list.d.ts +247 -0
  54. package/dist/react/agent-list.js +248 -0
  55. package/dist/react/approval-card.d.ts +272 -0
  56. package/dist/react/approval-card.js +372 -0
  57. package/dist/react/artifact-card.d.ts +38 -0
  58. package/dist/react/artifact-card.js +39 -0
  59. package/dist/react/avatar.d.ts +21 -0
  60. package/dist/react/avatar.js +33 -0
  61. package/dist/react/card-ledger.d.ts +30 -0
  62. package/dist/react/card-ledger.js +49 -0
  63. package/dist/react/chat-timing.d.ts +121 -0
  64. package/dist/react/chat-timing.js +229 -0
  65. package/dist/react/computer-view.d.ts +309 -0
  66. package/dist/react/computer-view.js +543 -0
  67. package/dist/react/computer-viewer.d.ts +175 -0
  68. package/dist/react/computer-viewer.js +555 -0
  69. package/dist/react/computer-wire.d.ts +178 -0
  70. package/dist/react/computer-wire.js +244 -0
  71. package/dist/react/connect-button.d.ts +145 -0
  72. package/dist/react/connect-button.js +212 -0
  73. package/dist/react/connection-request.d.ts +16 -0
  74. package/dist/react/connection-request.js +18 -0
  75. package/dist/react/connections-list.d.ts +90 -0
  76. package/dist/react/connections-list.js +76 -0
  77. package/dist/react/errors.d.ts +250 -0
  78. package/dist/react/errors.js +146 -0
  79. package/dist/react/files.d.ts +41 -0
  80. package/dist/react/files.js +78 -0
  81. package/dist/react/index.d.ts +35 -0
  82. package/dist/react/index.js +26 -0
  83. package/dist/react/limit-words.d.ts +80 -0
  84. package/dist/react/limit-words.js +53 -0
  85. package/dist/react/markdown.d.ts +42 -0
  86. package/dist/react/markdown.js +56 -0
  87. package/dist/react/md-parse.d.ts +106 -0
  88. package/dist/react/md-parse.js +638 -0
  89. package/dist/react/model-keys-card.d.ts +94 -0
  90. package/dist/react/model-keys-card.js +123 -0
  91. package/dist/react/reload.d.ts +211 -0
  92. package/dist/react/reload.js +339 -0
  93. package/dist/react/reveal.d.ts +17 -0
  94. package/dist/react/reveal.js +22 -0
  95. package/dist/react/schedule-editor.d.ts +107 -0
  96. package/dist/react/schedule-editor.js +172 -0
  97. package/dist/react/schedule-time.d.ts +66 -0
  98. package/dist/react/schedule-time.js +90 -0
  99. package/dist/react/styles.css +1274 -0
  100. package/dist/react/transport.d.ts +49 -0
  101. package/dist/react/transport.js +380 -0
  102. package/dist/react/use-connections.d.ts +155 -0
  103. package/dist/react/use-connections.js +231 -0
  104. package/dist/react/use-model-keys.d.ts +47 -0
  105. package/dist/react/use-model-keys.js +57 -0
  106. package/dist/react/use-threads.d.ts +63 -0
  107. package/dist/react/use-threads.js +73 -0
  108. package/dist/react/vault-form.d.ts +92 -0
  109. package/dist/react/vault-form.js +151 -0
  110. package/dist/schema.d.ts +47 -0
  111. package/dist/schema.js +16 -0
  112. package/dist/secrets.d.ts +15 -0
  113. package/dist/secrets.js +18 -0
  114. package/dist/stream.d.ts +129 -0
  115. package/dist/stream.js +192 -0
  116. package/dist/testing.d.ts +33 -0
  117. package/dist/testing.js +40 -0
  118. package/dist/webhooks.d.ts +31 -0
  119. package/dist/webhooks.js +72 -0
  120. package/package.json +85 -3
@@ -0,0 +1,212 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useContext, useEffect, useRef, useState } from "react";
4
+ import { AgentKitError } from "./agent-kit.js";
5
+ import { cardLedger, CardLedgerContext, connectKey } from "./card-ledger.js";
6
+ import { useNoteInView } from "./reveal.js";
7
+ import { isSetupRefusal, reportSetupRefusal, useConnections } from "./use-connections.js";
8
+ export const DEFAULT_CONNECT_LABELS = {
9
+ connect: "Connect {app}",
10
+ reconnect: "Reconnect {app}",
11
+ connectShort: "Connect",
12
+ reconnectShort: "Reconnect",
13
+ connectedShort: "Connected",
14
+ startAgain: "Start again",
15
+ opening: "Opening…",
16
+ waiting: "Finish connecting {app} in the new window or tab.",
17
+ connected: "{app} connected",
18
+ cancelled: "{app} wasn't connected.",
19
+ failed: "{app} couldn't be connected. Try again.",
20
+ expired: "That sign-in link expired.",
21
+ blocked: "Your browser blocked the new window.",
22
+ openLink: "Open {app} sign-in",
23
+ rateLimited: "Too many tries just now. Try again in a few minutes.",
24
+ startFailed: "Couldn't start connecting {app}. Try again later.",
25
+ setupRefused: "Connecting {app} isn't set up on our side yet. Please let us know, and we'll fix it.",
26
+ replaceRefused: "{app} was connected by someone else. Only an account admin can replace it.",
27
+ tainted: "Your assistant read content from outside before asking. Connect {app} only if you asked for this.",
28
+ done: "I connected {app}.",
29
+ doneCustom: "I connected it.",
30
+ };
31
+ export function connectLabelsOf(labels) {
32
+ const out = { ...DEFAULT_CONNECT_LABELS };
33
+ for (const [k, v] of Object.entries(labels ?? {}))
34
+ if (typeof v === "string")
35
+ out[k] = v;
36
+ return out;
37
+ }
38
+ export function carryOnOf(session, startedHere) {
39
+ return session?.status === "completed" && startedHere !== null && session.id === startedHere ? { send: true, startedHere: null } : { send: false, startedHere };
40
+ }
41
+ const PROBLEMS = new Set(["failed", "rateLimited", "startFailed", "setup", "replaceRefused"]);
42
+ export function connectionFor(connections, agent) {
43
+ return connections?.find((c) => agent === null || c.agents === null || c.agents.includes(agent)) ?? null;
44
+ }
45
+ export function connectViewOf(s) {
46
+ const live = connectionFor(s.connections, s.agent);
47
+ if (s.session?.status === "completed")
48
+ return { kind: "connected", account: live?.account.label ?? null };
49
+ if (s.starting)
50
+ return { kind: "starting" };
51
+ if (s.session?.status === "open")
52
+ return { kind: "waiting", link: s.blockedUrl };
53
+ if (live?.status === "active" && !s.session)
54
+ return { kind: "connected", account: live.account.label };
55
+ const reconnect = live?.status === "needs_reauth" || (s.reconnect && live?.status !== "active");
56
+ if (s.startError)
57
+ return { kind: "ready", again: false, note: s.startError, reconnect };
58
+ const st = s.session?.status;
59
+ if (st === "cancelled" || st === "failed" || st === "expired")
60
+ return { kind: "ready", again: st === "expired", note: st, reconnect };
61
+ return { kind: "ready", again: false, note: null, reconnect };
62
+ }
63
+ const RETURN_KEYS = ["connect_session", "status", "ol_connect"];
64
+ const SESSION_RE = /^cxs_[0-9A-Za-z]{1,64}$/;
65
+ export function redirectReturnPath(loc, app) {
66
+ const q = new URLSearchParams(loc.search);
67
+ for (const k of RETURN_KEYS)
68
+ q.delete(k);
69
+ q.set("ol_connect", app);
70
+ return `${loc.pathname}?${q.toString()}`;
71
+ }
72
+ export function takeReturnedSession(app, w) {
73
+ const q = new URLSearchParams(w.location.search);
74
+ const id = q.get("connect_session");
75
+ if (q.get("ol_connect") !== app || id === null || !SESSION_RE.test(id))
76
+ return null;
77
+ for (const k of RETURN_KEYS)
78
+ q.delete(k);
79
+ const rest = q.toString();
80
+ w.history.replaceState(null, "", `${w.location.pathname}${rest ? `?${rest}` : ""}${w.location.hash}`);
81
+ return id;
82
+ }
83
+ export function opensWindow(o) {
84
+ return o.mode !== "redirect" && o.auth !== "none";
85
+ }
86
+ const fill = (s, app) => s.replaceAll("{app}", app);
87
+ export function ConnectButton(props) {
88
+ const appName = props.appName ?? props.app;
89
+ const l = connectLabelsOf(props.labels);
90
+ const agent = props.agent ?? null;
91
+ const hook = useConnections({ app: props.app, api: props.api, fetch: props.fetch, onError: props.onError, enabled: props.connection === undefined });
92
+ const [starting, setStarting] = useState(false);
93
+ const [blockedUrl, setBlockedUrl] = useState(null);
94
+ const [startError, setStartError] = useState(null);
95
+ const startedHere = useRef(null);
96
+ const linkRef = useRef(null);
97
+ const connections = hook.connections ?? (props.connection ? [props.connection] : props.connection === null ? [] : null);
98
+ const shared = useContext(CardLedgerContext);
99
+ const [own] = useState(cardLedger);
100
+ const ledger = shared ?? own;
101
+ const key = connectKey({ app: props.app, agent });
102
+ const resume = hook.resume;
103
+ const resumeRef = useRef(resume);
104
+ resumeRef.current = resume;
105
+ useEffect(() => {
106
+ if (typeof window === "undefined")
107
+ return;
108
+ const id = takeReturnedSession(props.app, window);
109
+ if (id) {
110
+ startedHere.current = id;
111
+ resume(id);
112
+ }
113
+ }, [props.app, resume]);
114
+ useEffect(() => {
115
+ const pending = ledger.connectInFlight(key);
116
+ if (!pending)
117
+ return;
118
+ let live = true;
119
+ void pending.then((id) => {
120
+ if (!live || id === null || startedHere.current !== null)
121
+ return;
122
+ startedHere.current = id;
123
+ resumeRef.current(id);
124
+ });
125
+ return () => {
126
+ live = false;
127
+ };
128
+ }, [ledger, key]);
129
+ const onConnected = props.onConnected;
130
+ useEffect(() => {
131
+ const s = hook.session;
132
+ const next = carryOnOf(s, startedHere.current);
133
+ startedHere.current = next.startedHere;
134
+ if (next.send && s && ledger.connectEnded(key, s.id, true))
135
+ onConnected?.(props.app, appName);
136
+ else if (s && s.status !== "open" && s.status !== "completed")
137
+ ledger.connectEnded(key, s.id, false);
138
+ }, [hook.session, onConnected, props.app, appName, ledger, key]);
139
+ useEffect(() => {
140
+ if (blockedUrl)
141
+ linkRef.current?.focus();
142
+ }, [blockedUrl]);
143
+ async function start() {
144
+ setStartError(null);
145
+ setBlockedUrl(null);
146
+ const redirect = props.mode === "redirect" && typeof window !== "undefined";
147
+ const w = typeof window !== "undefined" && opensWindow({ mode: props.mode, auth: props.auth }) ? window.open("", "_blank", "popup,width=500,height=640") : null;
148
+ if (w) {
149
+ try {
150
+ w.document.title = l.opening;
151
+ w.document.body.textContent = l.opening;
152
+ }
153
+ catch {
154
+ }
155
+ }
156
+ setStarting(true);
157
+ let s;
158
+ const connecting = hook.connect(props.app, { agent, ...(redirect ? { returnPath: redirectReturnPath(window.location, props.app) } : {}) });
159
+ ledger.connectStarted(key, connecting.then((x) => x.id, () => null));
160
+ try {
161
+ s = await connecting;
162
+ }
163
+ catch (err) {
164
+ w?.close();
165
+ setStartError(isSetupRefusal(err) ? "setup" : err instanceof AgentKitError && err.code === "insufficient_role" ? "replaceRefused" : err instanceof AgentKitError && err.status === 429 ? "rateLimited" : "startFailed");
166
+ reportSetupRefusal(err);
167
+ props.onError?.(err);
168
+ setStarting(false);
169
+ return;
170
+ }
171
+ setStarting(false);
172
+ startedHere.current = s.id;
173
+ if (!s.url) {
174
+ w?.close();
175
+ return;
176
+ }
177
+ if (redirect) {
178
+ window.location.assign(s.url);
179
+ return;
180
+ }
181
+ if (w && !w.closed) {
182
+ w.opener = null;
183
+ w.location.href = s.url;
184
+ }
185
+ else {
186
+ setBlockedUrl(s.url);
187
+ }
188
+ }
189
+ const view = connectViewOf({ connections, session: hook.session, starting, blockedUrl, startError, agent, reconnect: props.reconnect === true });
190
+ return (_jsx(ConnectButtonView, { view: view, appName: appName, reason: props.reason, tainted: props.tainted === true, compact: props.compact === true, labels: l, onConnect: () => void start(), linkRef: linkRef, className: props.className }));
191
+ }
192
+ const button = { minHeight: 44 };
193
+ export function ConnectButtonView(p) {
194
+ const l = connectLabelsOf(p.labels);
195
+ const app = p.appName;
196
+ const v = p.view;
197
+ const status = v.kind === "connected"
198
+ ? `✓ ${p.compact ? l.connectedShort : fill(l.connected, app)}${v.account ? ` (${v.account})` : ""}`
199
+ : v.kind === "starting"
200
+ ? l.opening
201
+ : v.kind === "waiting"
202
+ ? v.link
203
+ ? l.blocked
204
+ : fill(l.waiting, app)
205
+ : v.note && !PROBLEMS.has(v.note)
206
+ ? fill(l[v.note === "setup" ? "setupRefused" : v.note], app)
207
+ : "";
208
+ const problem = v.kind === "ready" && v.note && PROBLEMS.has(v.note) ? v.note : null;
209
+ const statusInView = useNoteInView(v.kind === "connected" ? null : status);
210
+ const problemInView = useNoteInView(problem);
211
+ return (_jsxs("section", { "data-ol-connect": true, "data-ol-connect-state": v.kind, ...(p.compact ? { "data-ol-connect-compact": "true" } : {}), "aria-label": fill(l.connect, app), className: p.className, children: [p.compact || v.kind === "connected" ? null : _jsx("div", { "data-ol-connect-app": true, children: fill(v.kind === "ready" && v.reconnect ? l.reconnect : l.connect, app) }), p.reason && v.kind !== "connected" ? _jsx("p", { "data-ol-connect-reason": true, children: p.reason }) : null, p.tainted && v.kind !== "connected" ? (_jsx("p", { "data-ol-connect-warning": true, role: "note", children: fill(l.tainted, app) })) : null, _jsx("p", { "data-ol-connect-status": true, "aria-live": "polite", ref: statusInView, children: status }), problem ? (_jsx("p", { "data-ol-connect-error": problem, role: "alert", ref: problemInView, children: fill(l[problem === "setup" ? "setupRefused" : problem], app) })) : null, v.kind === "waiting" && v.link ? (_jsx("a", { "data-ol-connect-link": true, href: v.link, target: "_blank", rel: "noopener noreferrer", ref: p.linkRef, children: fill(l.openLink, app) })) : null, v.kind === "ready" ? (_jsx("button", { type: "button", "data-ol-connect-button": true, style: button, onClick: p.onConnect, children: v.again ? l.startAgain : v.reconnect ? l.reconnectShort : l.connectShort })) : null, v.kind === "waiting" ? (_jsx("button", { type: "button", "data-ol-connect-again": true, onClick: p.onConnect, children: l.startAgain })) : null] }));
212
+ }
@@ -0,0 +1,16 @@
1
+ /** An agent asking its person to connect an app: the chat's `data-connection-request` part, read defensively. */
2
+ export interface ConnectionRequest {
3
+ /** The catalog app id, e.g. google. */
4
+ app: string;
5
+ /** The app's name, from OpenLegion's catalog. */
6
+ appName: string;
7
+ /** The agent's one sentence: what it will do with the app. Plain text. */
8
+ reason: string;
9
+ /** The app is connected but needs signing in again. */
10
+ reconnect: boolean;
11
+ /** The agent read outside content before asking: the button says so. */
12
+ tainted: boolean;
13
+ /** agt_…: the agent that asked, so the connection is opened to it. */
14
+ agent: string | null;
15
+ }
16
+ export declare function connectionRequestOf(data: unknown): ConnectionRequest | null;
@@ -0,0 +1,18 @@
1
+ const APP_RE = /^[a-z][a-z0-9-]{1,47}$/;
2
+ const AGENT_RE = /^agt_[0-9A-Za-z]{1,64}$/;
3
+ export function connectionRequestOf(data) {
4
+ if (!data || typeof data !== "object" || Array.isArray(data))
5
+ return null;
6
+ const d = data;
7
+ if (d["object"] !== "connection_request" || typeof d["app"] !== "string" || !APP_RE.test(d["app"]))
8
+ return null;
9
+ const name = typeof d["app_name"] === "string" && d["app_name"].trim() !== "" ? d["app_name"].trim().slice(0, 80) : d["app"];
10
+ return {
11
+ app: d["app"],
12
+ appName: name,
13
+ reason: typeof d["reason"] === "string" ? d["reason"].slice(0, 200) : "",
14
+ reconnect: d["reconnect"] === true,
15
+ tainted: d["tainted"] === true,
16
+ agent: typeof d["agent"] === "string" && AGENT_RE.test(d["agent"]) ? d["agent"] : null,
17
+ };
18
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * `<ConnectionsList>`: the workspace's connected app accounts, one row each, with Reconnect when one needs signing
3
+ * in again and Disconnect (asked once). `<AppCatalog>`: the apps the workspace's people may connect, searchable, each
4
+ * with a Connect button; a row says its app's name once. Both act as the person your `resolve()` answers, and on
5
+ * one page they agree at once: connecting in the catalog shows in the list.
6
+ *
7
+ * A server your user added by its address is named by the name they gave it, its host beside it; it is
8
+ * reconnected and disconnected like any app. `<AppCatalog>` draws `<AddServerForm>` under its apps where the server
9
+ * says adding is on; `addServer={false}` takes it away.
10
+ */
11
+ import { type ReactNode } from "react";
12
+ import { type AddServerLabels } from "./add-server.tsx";
13
+ import { type ConnectButtonLabels } from "./connect-button.tsx";
14
+ import { type KitCatalogApp, type KitConnection, type KitCustomServers } from "./use-connections.ts";
15
+ export interface ConnectionsListLabels {
16
+ connected: string;
17
+ needsReconnect: string;
18
+ disconnect: string;
19
+ /** `{app}` is the app's name. */
20
+ confirm: string;
21
+ keep: string;
22
+ empty: string;
23
+ search: string;
24
+ noMatch: string;
25
+ }
26
+ export declare const DEFAULT_CONNECTIONS_LIST_LABELS: ConnectionsListLabels;
27
+ interface Shared {
28
+ /** The kit's base path. Default "/api/openlegion". */
29
+ api?: string | undefined;
30
+ fetch?: typeof fetch | undefined;
31
+ labels?: Partial<ConnectionsListLabels> | undefined;
32
+ connectLabels?: Partial<ConnectButtonLabels> | undefined;
33
+ onError?: ((err: Error) => void) | undefined;
34
+ className?: string | undefined;
35
+ }
36
+ /**
37
+ * What a connection's row calls it, and what it says beside. An app: the catalog's name, the account beside it. A server
38
+ * added by its address: the name it was given, its host beside it (the host alone when it has no name). Never the
39
+ * `custom-<slug>` id.
40
+ */
41
+ export declare function connectionName(c: KitConnection, names: readonly KitCatalogApp[] | null): {
42
+ name: string;
43
+ detail: string | null;
44
+ };
45
+ export declare function ConnectionsList(props: Shared): import("react").JSX.Element;
46
+ export interface ConnectionsListViewProps {
47
+ connections: readonly KitConnection[] | null;
48
+ names: readonly KitCatalogApp[] | null;
49
+ /** The connection whose Disconnect is being confirmed. */
50
+ asking: string | null;
51
+ error: string | null;
52
+ labels?: Partial<ConnectionsListLabels> | undefined;
53
+ className?: string | undefined;
54
+ onAsk: (id: string | null) => void;
55
+ onDisconnect: (c: KitConnection) => void;
56
+ reconnect: (c: KitConnection) => ReactNode;
57
+ }
58
+ export declare function ConnectionsListView(p: ConnectionsListViewProps): import("react").JSX.Element | null;
59
+ export interface AppCatalogProps extends Shared {
60
+ category?: string | undefined;
61
+ /** `false` hides "Add your own server" even where the server says it is on. It can never show it where the server says off. */
62
+ addServer?: boolean | undefined;
63
+ addServerLabels?: Partial<AddServerLabels> | undefined;
64
+ /** Once a server is added by its address: its connection (cxn_…) and name. */
65
+ onServerAdded?: ((connection: string | null, name: string) => void) | undefined;
66
+ }
67
+ export declare function AppCatalog(props: AppCatalogProps): import("react").JSX.Element;
68
+ export interface AppCatalogViewProps {
69
+ /** The apps to list (already filtered by `search`); null before the first read. */
70
+ apps: readonly KitCatalogApp[] | null;
71
+ connections: readonly KitConnection[] | null;
72
+ search: string;
73
+ onSearch: (search: string) => void;
74
+ labels?: Partial<ConnectionsListLabels> | undefined;
75
+ connectLabels?: Partial<ConnectButtonLabels> | undefined;
76
+ className?: string | undefined;
77
+ api?: string | undefined;
78
+ fetch?: typeof fetch | undefined;
79
+ onError?: ((err: Error) => void) | undefined;
80
+ onConnected?: (() => void) | undefined;
81
+ /** The catalog's `custom_servers`: the form is drawn only when this is {count, max} (null or undefined: off). */
82
+ customServers?: KitCustomServers | null | undefined;
83
+ /** `false` takes the form away; it never brings it back where `customServers` is null. */
84
+ addServer?: boolean | undefined;
85
+ addServerLabels?: Partial<AddServerLabels> | undefined;
86
+ onServerAdded?: ((connection: string | null, name: string) => void) | undefined;
87
+ }
88
+ /** The catalog as drawn: a search box, then a row per app that names it once, with its Connect button. */
89
+ export declare function AppCatalogView(p: AppCatalogViewProps): import("react").JSX.Element | null;
90
+ export {};
@@ -0,0 +1,76 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import { AddServerForm } from "./add-server.js";
5
+ import { agentKitErrorText } from "./agent-kit.js";
6
+ import { ConnectButton } from "./connect-button.js";
7
+ import { useNoteInView } from "./reveal.js";
8
+ import { useCatalog, useConnections } from "./use-connections.js";
9
+ export const DEFAULT_CONNECTIONS_LIST_LABELS = {
10
+ connected: "Connected",
11
+ needsReconnect: "Needs reconnecting",
12
+ disconnect: "Disconnect",
13
+ confirm: "Disconnect {app}? The assistants in this workspace lose access to it.",
14
+ keep: "Keep it",
15
+ empty: "No apps connected yet.",
16
+ search: "Search apps",
17
+ noMatch: "No apps match.",
18
+ };
19
+ const nameOf = (apps, id) => apps?.find((a) => a.id === id)?.name ?? id;
20
+ export function connectionName(c, names) {
21
+ if (c.source === "custom" || c.server) {
22
+ const host = c.server?.host ?? null;
23
+ const label = c.account.label;
24
+ if (label)
25
+ return { name: label, detail: host && host !== label ? host : null };
26
+ return { name: host ?? nameOf(names, c.app), detail: null };
27
+ }
28
+ return { name: nameOf(names, c.app), detail: c.account.label };
29
+ }
30
+ export function ConnectionsList(props) {
31
+ const l = { ...DEFAULT_CONNECTIONS_LIST_LABELS, ...props.labels };
32
+ const list = useConnections({ api: props.api, fetch: props.fetch, onError: props.onError });
33
+ const catalog = useCatalog({ api: props.api, fetch: props.fetch, onError: props.onError });
34
+ const [asking, setAsking] = useState(null);
35
+ const [error, setError] = useState(null);
36
+ const remove = async (c) => {
37
+ setError(null);
38
+ try {
39
+ await list.disconnect(c.id);
40
+ }
41
+ catch (err) {
42
+ if (err.code !== "connection_revoked")
43
+ setError(agentKitErrorText(err));
44
+ await list.refresh();
45
+ }
46
+ setAsking(null);
47
+ };
48
+ return (_jsx(ConnectionsListView, { connections: list.connections, names: catalog.apps, asking: asking, error: error, labels: l, className: props.className, onAsk: setAsking, onDisconnect: (c) => void remove(c), reconnect: (c) => (_jsx(ConnectButton, { app: c.app, appName: connectionName(c, catalog.apps).name, reconnect: true, connection: c, api: props.api, fetch: props.fetch, labels: props.connectLabels, onError: props.onError, onConnected: () => void list.refresh() })) }));
49
+ }
50
+ export function ConnectionsListView(p) {
51
+ const l = { ...DEFAULT_CONNECTIONS_LIST_LABELS, ...p.labels };
52
+ const errorInView = useNoteInView(p.error);
53
+ if (p.connections === null)
54
+ return null;
55
+ return (_jsxs("div", { "data-ol-connections": true, className: p.className, children: [p.error ? (_jsx("p", { "data-ol-connections-error": true, role: "alert", ref: errorInView, children: p.error })) : null, p.connections.length === 0 ? _jsx("p", { "data-ol-connections-empty": true, children: l.empty }) : null, _jsx("ul", { children: p.connections.map((c) => {
56
+ const { name: app, detail } = connectionName(c, p.names);
57
+ return (_jsxs("li", { "data-ol-connection": true, "data-ol-connection-status": c.status, "data-ol-connection-source": c.source, children: [_jsx("span", { "data-ol-connection-app": true, children: app }), detail ? _jsx("span", { "data-ol-connection-account": true, children: detail }) : null, _jsx("span", { "data-ol-connection-state": true, children: c.status === "active" ? l.connected : l.needsReconnect }), c.status === "needs_reauth" ? p.reconnect(c) : null, p.asking === c.id ? (_jsxs("span", { "data-ol-connection-confirm": true, role: "group", "aria-label": l.disconnect, children: [_jsx("span", { children: l.confirm.replaceAll("{app}", app) }), _jsx("button", { type: "button", onClick: () => p.onDisconnect(c), children: l.disconnect }), _jsx("button", { type: "button", onClick: () => p.onAsk(null), children: l.keep })] })) : (_jsx("button", { type: "button", "data-ol-connection-disconnect": true, onClick: () => p.onAsk(c.id), children: l.disconnect }))] }, c.id));
58
+ }) })] }));
59
+ }
60
+ export function AppCatalog(props) {
61
+ const l = { ...DEFAULT_CONNECTIONS_LIST_LABELS, ...props.labels };
62
+ const [search, setSearch] = useState("");
63
+ const catalog = useCatalog({ api: props.api, fetch: props.fetch, onError: props.onError, category: props.category, search });
64
+ const list = useConnections({ api: props.api, fetch: props.fetch, onError: props.onError });
65
+ return (_jsx(AppCatalogView, { apps: catalog.apps, connections: list.connections, customServers: catalog.customServers, addServer: props.addServer, addServerLabels: props.addServerLabels, onServerAdded: (connection, name) => {
66
+ void list.refresh();
67
+ props.onServerAdded?.(connection, name);
68
+ }, search: search, onSearch: setSearch, labels: l, connectLabels: props.connectLabels, className: props.className, api: props.api, fetch: props.fetch, onError: props.onError, onConnected: () => void list.refresh() }));
69
+ }
70
+ export function AppCatalogView(p) {
71
+ const l = { ...DEFAULT_CONNECTIONS_LIST_LABELS, ...p.labels };
72
+ if (p.apps === null || p.connections === null)
73
+ return null;
74
+ const connections = p.connections;
75
+ return (_jsxs("div", { "data-ol-catalog": true, className: p.className, children: [_jsx("input", { type: "search", "data-ol-catalog-search": true, "aria-label": l.search, placeholder: l.search, value: p.search, onChange: (e) => p.onSearch(e.target.value) }), p.apps.length === 0 ? _jsx("p", { "data-ol-catalog-empty": true, children: l.noMatch }) : null, _jsx("ul", { children: p.apps.map((a) => (_jsxs("li", { "data-ol-catalog-app": true, children: [a.logo ? _jsx("img", { "data-ol-catalog-icon": true, src: a.logo, alt: "", width: 24, height: 24 }) : _jsx("span", { "data-ol-catalog-icon": true, "aria-hidden": "true", children: a.name.slice(0, 1) }), _jsx("span", { "data-ol-catalog-name": true, children: a.name }), _jsx("span", { "data-ol-catalog-description": true, children: a.description }), _jsx(ConnectButton, { app: a.id, appName: a.name, auth: a.auth.kind, compact: true, connection: connections.find((c) => c.app === a.id) ?? null, api: p.api, fetch: p.fetch, labels: p.connectLabels, onError: p.onError, onConnected: p.onConnected })] }, a.id))) }), p.customServers && p.addServer !== false ? (_jsx(AddServerForm, { customServers: p.customServers, api: p.api, fetch: p.fetch, labels: p.addServerLabels, onError: p.onError, onAdded: p.onServerAdded })) : null] }));
76
+ }