@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,90 @@
1
+ import { type KitConnectSession, type KitCustomServers } from "./use-connections.ts";
2
+ /** Every string the form shows. `{name}` is the server's name (or its address's host); `{count}` and `{max}` in `full`. */
3
+ export interface AddServerLabels {
4
+ title: string;
5
+ address: string;
6
+ addressHint: string;
7
+ name: string;
8
+ nameHint: string;
9
+ submit: string;
10
+ startAgain: string;
11
+ opening: string;
12
+ waiting: string;
13
+ blocked: string;
14
+ openLink: string;
15
+ added: string;
16
+ cancelled: string;
17
+ expired: string;
18
+ failed: string;
19
+ needsOauthApp: string;
20
+ checkFailed: string;
21
+ limit: string;
22
+ full: string;
23
+ invalidAddress: string;
24
+ notEnabled: string;
25
+ rateLimited: string;
26
+ /** A refusal to start that a retry can't fix: the network or the server. */
27
+ startFailed: string;
28
+ /** A refusal only your setup can fix (your page's origin isn't one of your return origins, …): no "try again". */
29
+ setupRefused: string;
30
+ /** Someone else added this server, and only an owner or admin may replace it (403 `insufficient_role`). */
31
+ replaceRefused: string;
32
+ }
33
+ export declare const DEFAULT_ADD_SERVER_LABELS: AddServerLabels;
34
+ /** The one line under the form, by what happened. */
35
+ export type AddServerNote = "opening" | "waiting" | "blocked" | "added" | "cancelled" | "expired" | "failed" | "needsOauthApp" | "checkFailed" | "limit" | "invalidAddress" | "notEnabled" | "rateLimited" | "startFailed" | "setupRefused" | "replaceRefused";
36
+ /** What the form shows, from what it knows. */
37
+ export type AddServerView = {
38
+ kind: "off";
39
+ } | {
40
+ kind: "full";
41
+ count: number;
42
+ max: number;
43
+ note?: "added";
44
+ name?: string | null;
45
+ } | {
46
+ kind: "form";
47
+ note: AddServerNote | null;
48
+ invalid: boolean;
49
+ waiting: boolean;
50
+ link: string | null;
51
+ name: string | null;
52
+ };
53
+ export declare function addServerViewOf(s: {
54
+ /** The catalog's `custom_servers`: null, off; undefined, not read yet (also off). */
55
+ customServers: KitCustomServers | null | undefined;
56
+ starting: boolean;
57
+ session: KitConnectSession | null;
58
+ startError: Error | null;
59
+ blockedUrl: string | null;
60
+ }): AddServerView;
61
+ /** The name the words use: the name typed, else the address's host, else "The server". */
62
+ export declare function serverNameOf(url: string, name: string): string;
63
+ export interface AddServerFormViewProps {
64
+ view: AddServerView;
65
+ url: string;
66
+ name: string;
67
+ onUrl: (url: string) => void;
68
+ onName: (name: string) => void;
69
+ onSubmit: () => void;
70
+ labels?: Partial<AddServerLabels> | undefined;
71
+ linkRef?: {
72
+ current: HTMLAnchorElement | null;
73
+ } | undefined;
74
+ className?: string | undefined;
75
+ }
76
+ /** The form as drawn for one state: no network, for your tests and stories. */
77
+ export declare function AddServerFormView(p: AddServerFormViewProps): import("react").JSX.Element | null;
78
+ export interface AddServerFormProps {
79
+ /** The catalog's `custom_servers`, when your page already read it (`useCatalog().customServers`): the form reads none. */
80
+ customServers?: KitCustomServers | null | undefined;
81
+ /** The kit's base path. Default "/api/openlegion". */
82
+ api?: string | undefined;
83
+ fetch?: typeof fetch | undefined;
84
+ labels?: Partial<AddServerLabels> | undefined;
85
+ /** Once a server is added: its connection (cxn_…) and name. */
86
+ onAdded?: ((connection: string | null, name: string) => void) | undefined;
87
+ onError?: ((err: Error) => void) | undefined;
88
+ className?: string | undefined;
89
+ }
90
+ export declare function AddServerForm(props: AddServerFormProps): import("react").JSX.Element;
@@ -0,0 +1,183 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useId, useRef, useState } from "react";
4
+ import { AgentKitError } from "./agent-kit.js";
5
+ import { useNoteInView } from "./reveal.js";
6
+ import { isSetupRefusal, reportSetupRefusal, useCatalog, useConnections } from "./use-connections.js";
7
+ export const DEFAULT_ADD_SERVER_LABELS = {
8
+ title: "Add your own server",
9
+ address: "Server address",
10
+ addressHint: "The address of an MCP server. It starts with https://.",
11
+ name: "Name (optional)",
12
+ nameHint: "What you and your assistants will call it. Leave it empty to use the address.",
13
+ submit: "Add server",
14
+ startAgain: "Start again",
15
+ opening: "Opening…",
16
+ waiting: "Finish adding {name} in the new window or tab.",
17
+ blocked: "Your browser blocked the new window.",
18
+ openLink: "Open the page to add {name}",
19
+ added: "{name} was added. Each of its tools asks for approval before it runs.",
20
+ cancelled: "{name} wasn't added.",
21
+ expired: "That page expired. Try again.",
22
+ failed: "{name} couldn't be added. Try again.",
23
+ needsOauthApp: "{name} doesn't let new apps sign in to it, so it can't be added here.",
24
+ checkFailed: "{name} didn't pass the safety checks on its tools, so it wasn't added.",
25
+ limit: "You've added the most servers allowed. Disconnect one to add another.",
26
+ full: "You've added {count} of {max} servers. Disconnect one to add another.",
27
+ invalidAddress: "Enter an address that starts with https:// and names a public server, like https://mcp.example.com.",
28
+ notEnabled: "Adding your own servers isn't turned on here.",
29
+ rateLimited: "Too many tries just now. Try again in a few minutes.",
30
+ startFailed: "Couldn't start adding {name}. Try again later.",
31
+ setupRefused: "Adding servers isn't set up on our side yet. Please let us know, and we'll fix it.",
32
+ replaceRefused: "{name} was added by someone else. Only an account admin can replace it.",
33
+ };
34
+ const PROBLEMS = new Set(["failed", "needsOauthApp", "checkFailed", "limit", "invalidAddress", "notEnabled", "rateLimited", "startFailed", "setupRefused", "replaceRefused"]);
35
+ function endedNote(s) {
36
+ if (s.status === "completed")
37
+ return "added";
38
+ if (s.status === "cancelled")
39
+ return "cancelled";
40
+ if (s.status === "expired")
41
+ return "expired";
42
+ if (s.status !== "failed")
43
+ return null;
44
+ return s.failure_code === "needs_oauth_app" ? "needsOauthApp" : s.failure_code === "app_check_failed" ? "checkFailed" : s.failure_code === "custom_server_limit_reached" ? "limit" : "failed";
45
+ }
46
+ function startNote(err) {
47
+ const e = err instanceof AgentKitError ? err : null;
48
+ if (e && (e.code === "invalid_server" || (e.code === "parameter_invalid" && (e.param ?? "").startsWith("server"))))
49
+ return { note: "invalidAddress", invalid: true };
50
+ if (e?.code === "app_not_enabled")
51
+ return { note: "notEnabled", invalid: false };
52
+ if (e?.code === "custom_server_limit_reached")
53
+ return { note: "limit", invalid: false };
54
+ if (e?.status === 429)
55
+ return { note: "rateLimited", invalid: false };
56
+ if (e?.code === "insufficient_role")
57
+ return { note: "replaceRefused", invalid: false };
58
+ if (isSetupRefusal(err))
59
+ return { note: "setupRefused", invalid: false };
60
+ return { note: "startFailed", invalid: false };
61
+ }
62
+ export function addServerViewOf(s) {
63
+ if (!s.customServers)
64
+ return { kind: "off" };
65
+ const ended = s.session && s.session.status !== "open" ? endedNote(s.session) : null;
66
+ const name = s.session?.server?.name ?? null;
67
+ if (s.customServers.count >= s.customServers.max && !s.starting && s.session?.status !== "open")
68
+ return { kind: "full", count: s.customServers.count, max: s.customServers.max, ...(ended === "added" ? { note: "added", name } : {}) };
69
+ if (s.starting)
70
+ return { kind: "form", note: "opening", invalid: false, waiting: false, link: null, name };
71
+ if (s.startError)
72
+ return { kind: "form", ...startNote(s.startError), waiting: false, link: null, name };
73
+ if (s.session?.status === "open")
74
+ return { kind: "form", note: s.blockedUrl ? "blocked" : "waiting", invalid: false, waiting: true, link: s.blockedUrl, name };
75
+ return { kind: "form", note: ended, invalid: false, waiting: false, link: null, name };
76
+ }
77
+ export function serverNameOf(url, name) {
78
+ if (name.trim() !== "")
79
+ return name.trim();
80
+ try {
81
+ return new URL(url.trim()).host || "The server";
82
+ }
83
+ catch {
84
+ return "The server";
85
+ }
86
+ }
87
+ const field = { display: "flex", flexDirection: "column", gap: "var(--ol-field-gap, 0.25rem)" };
88
+ const hint = { fontSize: "var(--ol-small, 0.875em)", opacity: 0.7 };
89
+ export function AddServerFormView(p) {
90
+ const l = { ...DEFAULT_ADD_SERVER_LABELS, ...p.labels };
91
+ const id = useId();
92
+ const v = p.view;
93
+ const status = v.kind === "form" && v.note && !PROBLEMS.has(v.note) ? v.note : "";
94
+ const problem = v.kind === "form" && v.note && PROBLEMS.has(v.note) ? v.note : null;
95
+ const statusInView = useNoteInView(status);
96
+ const problemInView = useNoteInView(problem);
97
+ const addedInView = useNoteInView();
98
+ if (v.kind === "off")
99
+ return null;
100
+ const who = v.name ? v.name : serverNameOf(p.url, p.name);
101
+ const fill = (s) => s.replaceAll("{name}", who);
102
+ const title = (_jsx("div", { id: `${id}-title`, "data-ol-add-server-title": true, children: l.title }));
103
+ if (v.kind === "full") {
104
+ return (_jsxs("section", { "data-ol-add-server": true, "data-ol-add-server-state": "full", "aria-labelledby": `${id}-title`, className: p.className, children: [title, v.note ? (_jsx("p", { role: "status", ref: addedInView, children: fill(l.added) })) : null, _jsx("p", { "data-ol-add-server-full": true, children: l.full.replace("{count}", String(v.count)).replace("{max}", String(v.max)) })] }));
105
+ }
106
+ const submit = (e) => {
107
+ e.preventDefault();
108
+ if (v.note !== "opening")
109
+ p.onSubmit();
110
+ };
111
+ return (_jsxs("section", { "data-ol-add-server": true, "data-ol-add-server-state": v.note ?? "ready", "aria-labelledby": `${id}-title`, className: p.className, children: [title, _jsxs("form", { "data-ol-add-server-form": true, onSubmit: submit, style: { display: "flex", flexDirection: "column", gap: "var(--ol-gap, 0.75rem)" }, children: [_jsxs("div", { style: field, children: [_jsx("label", { htmlFor: `${id}-url`, children: l.address }), _jsx("input", { id: `${id}-url`, type: "url", required: true, inputMode: "url", autoComplete: "url", spellCheck: false, placeholder: "https://", "data-ol-add-server-url": true, value: p.url, "aria-invalid": v.invalid ? true : undefined, "aria-describedby": [`${id}-url-hint`, v.invalid ? `${id}-error` : null].filter(Boolean).join(" "), onChange: (e) => p.onUrl(e.target.value) }), _jsx("span", { id: `${id}-url-hint`, "data-ol-add-server-hint": true, style: hint, children: l.addressHint })] }), _jsxs("div", { style: field, children: [_jsx("label", { htmlFor: `${id}-name`, children: l.name }), _jsx("input", { id: `${id}-name`, type: "text", autoComplete: "off", maxLength: 80, "data-ol-add-server-name": true, value: p.name, "aria-describedby": `${id}-name-hint`, onChange: (e) => p.onName(e.target.value) }), _jsx("span", { id: `${id}-name-hint`, "data-ol-add-server-hint": true, style: hint, children: l.nameHint })] }), _jsx("p", { id: `${id}-status`, "data-ol-add-server-status": true, "aria-live": "polite", style: { margin: 0 }, ref: statusInView, children: v.note && !PROBLEMS.has(v.note) ? fill(l[v.note]) : "" }), v.note && PROBLEMS.has(v.note) ? (_jsx("p", { id: `${id}-error`, "data-ol-add-server-error": v.note, role: "alert", style: { margin: 0 }, ref: problemInView, children: fill(l[v.note]) })) : null, v.link ? (_jsx("a", { "data-ol-add-server-link": true, href: v.link, target: "_blank", rel: "noopener noreferrer", ref: p.linkRef, children: fill(l.openLink) })) : null, _jsx("div", { children: _jsx("button", { type: "submit", "data-ol-add-server-submit": true, disabled: v.note === "opening", children: v.waiting ? l.startAgain : l.submit }) })] })] }));
112
+ }
113
+ export function AddServerForm(props) {
114
+ const own = useCatalog({ api: props.api, fetch: props.fetch, onError: props.onError, enabled: props.customServers === undefined });
115
+ const customServers = props.customServers !== undefined ? props.customServers : own.customServers;
116
+ const hook = useConnections({ api: props.api, fetch: props.fetch, onError: props.onError, enabled: false });
117
+ const [url, setUrl] = useState("");
118
+ const [name, setName] = useState("");
119
+ const [starting, setStarting] = useState(false);
120
+ const [startError, setStartError] = useState(null);
121
+ const [blockedUrl, setBlockedUrl] = useState(null);
122
+ const startedHere = useRef(null);
123
+ const linkRef = useRef(null);
124
+ const l = { ...DEFAULT_ADD_SERVER_LABELS, ...props.labels };
125
+ const onAdded = props.onAdded;
126
+ useEffect(() => {
127
+ const s = hook.session;
128
+ if (!s || s.id !== startedHere.current || s.status !== "completed")
129
+ return;
130
+ startedHere.current = null;
131
+ setUrl("");
132
+ setName("");
133
+ onAdded?.(s.connection, s.server?.name ?? "");
134
+ }, [hook.session, onAdded]);
135
+ useEffect(() => {
136
+ if (blockedUrl)
137
+ linkRef.current?.focus();
138
+ }, [blockedUrl]);
139
+ async function start() {
140
+ setStartError(null);
141
+ setBlockedUrl(null);
142
+ const w = typeof window !== "undefined" ? window.open("", "_blank", "popup,width=500,height=640") : null;
143
+ if (w) {
144
+ try {
145
+ w.document.title = l.opening;
146
+ w.document.body.textContent = l.opening;
147
+ }
148
+ catch {
149
+ }
150
+ }
151
+ setStarting(true);
152
+ let s;
153
+ try {
154
+ s = await hook.connectServer({ url: url.trim(), ...(name.trim() ? { name: name.trim() } : {}) });
155
+ }
156
+ catch (err) {
157
+ w?.close();
158
+ setStartError(err);
159
+ reportSetupRefusal(err);
160
+ props.onError?.(err);
161
+ setStarting(false);
162
+ return;
163
+ }
164
+ setStarting(false);
165
+ startedHere.current = s.id;
166
+ if (!s.url) {
167
+ w?.close();
168
+ return;
169
+ }
170
+ if (w && !w.closed) {
171
+ w.opener = null;
172
+ w.location.href = s.url;
173
+ }
174
+ else {
175
+ setBlockedUrl(s.url);
176
+ }
177
+ }
178
+ const view = addServerViewOf({ customServers, starting, session: hook.session, startError, blockedUrl });
179
+ return (_jsx(AddServerFormView, { view: view, url: url, name: name, onUrl: (u) => {
180
+ setUrl(u);
181
+ setStartError(null);
182
+ }, onName: setName, onSubmit: () => void start(), labels: props.labels, linkRef: linkRef, className: props.className }));
183
+ }