@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,201 @@
|
|
|
1
|
+
import { OpenLegion } from "./client.ts";
|
|
2
|
+
import { type OpenLegionErrorLimit } from "./errors.ts";
|
|
3
|
+
import type { WebhookEvent } from "./events.ts";
|
|
4
|
+
import type { Action, EventType, TemplateSpec } from "./generated/api.ts";
|
|
5
|
+
import { type ConnectorRefInput, type Template, type Tool } from "./kit.ts";
|
|
6
|
+
import type { SecretInput } from "./secrets.ts";
|
|
7
|
+
export interface WebhookContext {
|
|
8
|
+
/** OpenLegion-Delivery: `whd_…`, the same on every retry and resend of one delivery (as `GET /webhook_endpoints/{id}/deliveries` shows it). Dedupe on `event.id`. */
|
|
9
|
+
delivery: string | null;
|
|
10
|
+
request: Request;
|
|
11
|
+
}
|
|
12
|
+
export type WebhookHandlers = {
|
|
13
|
+
[T in EventType]?: (event: WebhookEvent<T>, ctx: WebhookContext) => unknown;
|
|
14
|
+
} & {
|
|
15
|
+
/** Any type without its own handler. */
|
|
16
|
+
"*"?: (event: WebhookEvent, ctx: WebhookContext) => unknown;
|
|
17
|
+
};
|
|
18
|
+
/** What your `resolve` answers: whose workspace a browser request is for, and as which of your users. */
|
|
19
|
+
export interface EndUserScope {
|
|
20
|
+
/** The workspace (ws_…) of the customer this request is for. */
|
|
21
|
+
workspace: string;
|
|
22
|
+
/** Your user's id, when the agent should act as them (OpenLegion-Subject). */
|
|
23
|
+
subject?: string;
|
|
24
|
+
/**
|
|
25
|
+
* That user's name, as your product shows it: sent with `subject` as OpenLegion-Subject-Name on every request the
|
|
26
|
+
* kit makes for them, and kept by OpenLegion as their name in your organization (the agent is told it; history and
|
|
27
|
+
* the audit trail show it). 1-120 characters once trimmed; blank sends none. The kit never makes one up: pass a
|
|
28
|
+
* name, never an email address. `null` clears it (OpenLegion-Subject-Name-Clear: true); left out, the name stays.
|
|
29
|
+
*/
|
|
30
|
+
displayName?: string | null;
|
|
31
|
+
}
|
|
32
|
+
export interface HandlerOptions {
|
|
33
|
+
/** Your template (`defineTemplate`): its tools are the tool server's. */
|
|
34
|
+
template?: Template;
|
|
35
|
+
/** The tool server's tools, when you serve them without a template (default: `template.tools`). */
|
|
36
|
+
tools?: Readonly<Record<string, Tool>>;
|
|
37
|
+
/** Your connector's signing secret (two during a rotation). Default: env OPENLEGION_CONNECTOR_SECRET. */
|
|
38
|
+
connectorSecret?: SecretInput;
|
|
39
|
+
/** Your webhook endpoint's signing secret (two during a rotation). Default: env OPENLEGION_WEBHOOK_SECRET. */
|
|
40
|
+
webhookSecret?: SecretInput;
|
|
41
|
+
/** Handlers by event type. A delivery with no handler is acknowledged (200). A handler that throws is 500, and retried. */
|
|
42
|
+
webhooks?: WebhookHandlers;
|
|
43
|
+
/**
|
|
44
|
+
* REQUIRED to open the browser routes (chat, runs, vault); absent, they are 404. Read YOUR session from the
|
|
45
|
+
* request (your cookie, your auth) and answer the workspace it may use, or null to refuse (401). Never trust
|
|
46
|
+
* an id the browser sends. Do not read the request's body here: the route reads it after you answer.
|
|
47
|
+
*/
|
|
48
|
+
resolve?: (req: Request) => EndUserScope | null | Promise<EndUserScope | null>;
|
|
49
|
+
/**
|
|
50
|
+
* Origins besides the request's own that may call the browser routes, each exactly `scheme://host[:port]`
|
|
51
|
+
* (`https://admin.example.com`: no path, no trailing slash, no `*`). A browser call from any other origin is
|
|
52
|
+
* 403. Matched as whole strings, never by prefix or suffix. A bad entry, or a list without `resolve`, throws
|
|
53
|
+
* at `createHandler`.
|
|
54
|
+
*/
|
|
55
|
+
allowedOrigins?: readonly string[];
|
|
56
|
+
/** The client the browser routes use. Default: `new OpenLegion()` (env OPENLEGION_API_KEY), made on first use. */
|
|
57
|
+
client?: OpenLegion;
|
|
58
|
+
/** Where the route is mounted. Default "/api/openlegion". */
|
|
59
|
+
basePath?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Where OpenLegion's hosted Connect page sends your user back. Default: the calling page's origin +
|
|
62
|
+
* `{basePath}/connect_return`. Its origin must be one of your registered return origins (POST /connect_settings).
|
|
63
|
+
*/
|
|
64
|
+
connectReturnUrl?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Who may use the model-key routes (`{basePath}/model_keys`): a person's own Anthropic or OpenAI key pays for
|
|
67
|
+
* every conversation in the workspace. Called with what `resolve` answered and the request; answer true to let
|
|
68
|
+
* this person see, save and remove the workspace's key. For anyone else the routes answer as if they weren't
|
|
69
|
+
* there (the handler's 404), whatever the method; a throw counts as no (and goes to `onError`). Absent, everyone
|
|
70
|
+
* `resolve` lets in may.
|
|
71
|
+
*/
|
|
72
|
+
allowModelKeys?: (who: EndUserScope, req: Request) => boolean | Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* Which model presets a person may choose (a plan's): called with what `resolve` answered, a preset the template
|
|
75
|
+
* allows (`fast`, `reasoning`, `frontier`; `background` only if a template allows it), and the request. Answer true
|
|
76
|
+
* to let them. The kit's agent routes then offer only those (every `customizable.model_tier.allowed` answered is
|
|
77
|
+
* narrowed, so `<AgentEditor>` shows only them), and refuse a save naming another (403 `model_tier_not_allowed`;
|
|
78
|
+
* the editor says "That choice isn't available to you here. Choose another."). Following the template's own
|
|
79
|
+
* preset is never asked. Asked once per preset per request; a throw counts as no (and goes to `onError`).
|
|
80
|
+
* Absent, everyone `resolve` lets in may choose what the template allows. The API's bounds stay the backstop.
|
|
81
|
+
*
|
|
82
|
+
* AUTO is asked as `tier` "auto" (where the template's `customizable.model_tier.auto` is true). No: the page reads
|
|
83
|
+
* Auto as not offered, and a save to it is refused. Yes: a save to Auto routes among exactly the presets this hook
|
|
84
|
+
* says yes to (inside the template's, never `background`). The handler sets the write's `auto_presets` from your
|
|
85
|
+
* answers and drops any a browser sent, so Auto never reaches a model this person couldn't pick by hand. A hook
|
|
86
|
+
* written before Auto existed that answers only the presets it knows says no to "auto": Auto stays off.
|
|
87
|
+
*
|
|
88
|
+
* WHEN WHAT A PERSON MAY USE CHANGES, SAVE THEIR AGENTS AGAIN: a stored choice, and an Auto agent's set of models,
|
|
89
|
+
* stay as they were saved. This hook is asked when a person saves, never on a run.
|
|
90
|
+
*/
|
|
91
|
+
allowModelTier?: (who: EndUserScope, tier: "background" | "fast" | "reasoning" | "frontier" | "auto", req: Request) => boolean | Promise<boolean>;
|
|
92
|
+
/** Errors your code threw, and misconfiguration. Default: console.error. Never sent to OpenLegion, a browser or a model. */
|
|
93
|
+
onError?: (err: unknown, where: string) => void;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* JSON with every object's keys sorted, at every depth; array order is kept and `undefined` members are
|
|
97
|
+
* dropped. A template definition's `hash` is the sha256 of `canonicalJson(version)`, so the hash does not
|
|
98
|
+
* depend on how a spec was written down, and two specs compare equal after a jsonb round trip (jsonb does
|
|
99
|
+
* not keep key order). The CLI compares template versions with this function.
|
|
100
|
+
*/
|
|
101
|
+
export declare function canonicalJson(value: unknown): string;
|
|
102
|
+
/** What `POST {basePath}/template` answers. */
|
|
103
|
+
export interface TemplateDefinitionObject {
|
|
104
|
+
object: "template_definition";
|
|
105
|
+
slug: string;
|
|
106
|
+
name: string;
|
|
107
|
+
/** The template version to push: `template.toTemplateSpec(connector)`. */
|
|
108
|
+
version: TemplateSpec;
|
|
109
|
+
/** Per tool, digests of what the model reads (title and description) and of its input schema. */
|
|
110
|
+
tools: Array<{
|
|
111
|
+
name: string;
|
|
112
|
+
description_sha256: string;
|
|
113
|
+
input_schema_sha256: string;
|
|
114
|
+
}>;
|
|
115
|
+
/** sha256 of `version` as canonical JSON: a different hash is a different template version. */
|
|
116
|
+
hash: string;
|
|
117
|
+
}
|
|
118
|
+
/** The definition `POST {basePath}/template` answers for this template and connector. */
|
|
119
|
+
export declare function templateDefinition(template: Template, connector: ConnectorRefInput | null): Promise<TemplateDefinitionObject>;
|
|
120
|
+
/** What `GET {basePath}/runs/{run}` answers: what a reload draws for a person's message whose run left no answer. */
|
|
121
|
+
/**
|
|
122
|
+
* `GET {basePath}/approvals/{apr}`: what the chat's approval card shows, read as the person resolve() answered. The
|
|
123
|
+
* platform's words for what the agent wants to do (`title`, `fields`) and the `action_hash` to decide it with;
|
|
124
|
+
* never the action's input, its cost or your `metadata`.
|
|
125
|
+
*/
|
|
126
|
+
export interface ApprovalCardObject {
|
|
127
|
+
object: "approval";
|
|
128
|
+
/** apr_… */
|
|
129
|
+
id: string;
|
|
130
|
+
status: "pending" | "approved" | "rejected" | "expired";
|
|
131
|
+
title: string | null;
|
|
132
|
+
/**
|
|
133
|
+
* Every fact of the action's input. `detail: true`: draw it behind the card's details, not up front.
|
|
134
|
+
* `truncated: true`: the value was longer than 20,000 characters and holds its first 20,000 and an ellipsis;
|
|
135
|
+
* Approve allows the whole of it. `from_page: true`: a web page wrote this value (a held browser act's control, its
|
|
136
|
+
* containers, its page); the card draws it in quotes as the page's words, never as its own.
|
|
137
|
+
*/
|
|
138
|
+
fields: Array<{
|
|
139
|
+
label: string;
|
|
140
|
+
value: string;
|
|
141
|
+
detail?: boolean;
|
|
142
|
+
truncated?: boolean;
|
|
143
|
+
from_page?: boolean;
|
|
144
|
+
}>;
|
|
145
|
+
expires_at: string | null;
|
|
146
|
+
/** Send it back with the decision; null for a question. */
|
|
147
|
+
action_hash: string | null;
|
|
148
|
+
/** Whether the person resolve() answered may decide it (the platform's `can_decide`); null on a decision's answer. */
|
|
149
|
+
can_decide: boolean | null;
|
|
150
|
+
/**
|
|
151
|
+
* A held browser act's browser session (`cps_…`, the platform's `action.computer_session`): the id on that session's
|
|
152
|
+
* `data-computer` part. Absent for every other card. The act's input itself is never sent.
|
|
153
|
+
*/
|
|
154
|
+
computer_session?: string;
|
|
155
|
+
/**
|
|
156
|
+
* On a decision's answer only: the decision was taken, and no run follows it now (the workspace cannot run, or the
|
|
157
|
+
* agent is paused). The refusal a send refused now carries, in the same words: `code`, the end user's `message`,
|
|
158
|
+
* and the `limit` on `cap_reached`. Never the operator's sentence. Absent when a run follows.
|
|
159
|
+
*/
|
|
160
|
+
run_refused?: {
|
|
161
|
+
type: "refusal";
|
|
162
|
+
code: string;
|
|
163
|
+
message: string;
|
|
164
|
+
limit?: OpenLegionErrorLimit;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* On an approved card only: what came of the approved action, so the card can follow it until it has an outcome
|
|
168
|
+
* (`outcome` null while it waits or runs). `message` is the end user's sentence when it did not succeed
|
|
169
|
+
* (`error.message`); never the operator's, and never its input. Absent on a pending, rejected or expired card.
|
|
170
|
+
*/
|
|
171
|
+
action?: {
|
|
172
|
+
status: Action["status"];
|
|
173
|
+
outcome: Action["outcome"];
|
|
174
|
+
message: string | null;
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
export interface RunOutcomeObject {
|
|
178
|
+
object: "run_outcome";
|
|
179
|
+
/** run_… */
|
|
180
|
+
id: string;
|
|
181
|
+
status: "queued" | "running" | "completed" | "failed" | "cancelled" | "settling";
|
|
182
|
+
/** The run's stable error code, when it failed. */
|
|
183
|
+
code: string | null;
|
|
184
|
+
/** The end user's sentence (`error.message`), when it failed. Never the operator's. */
|
|
185
|
+
message: string | null;
|
|
186
|
+
/** RUN16 (A): a cap refusal's limit (`error.limit`), so a reload says it in the person's own zone; else null. */
|
|
187
|
+
limit: OpenLegionErrorLimit | null;
|
|
188
|
+
/** When it started and ended (RFC 3339), null until then. Runs that one unit of work answered share both. */
|
|
189
|
+
started_at: string | null;
|
|
190
|
+
ended_at: string | null;
|
|
191
|
+
/** Once the run ended (completed or failed): its actions, in the order the API lists them. Else empty. */
|
|
192
|
+
actions: Array<{
|
|
193
|
+
id: string;
|
|
194
|
+
tool: string;
|
|
195
|
+
status: string;
|
|
196
|
+
outcome: string | null;
|
|
197
|
+
message: string | null; /** apr_…: its newest approval, if it needed one. */
|
|
198
|
+
approval: string | null;
|
|
199
|
+
}>;
|
|
200
|
+
}
|
|
201
|
+
export declare function createHandler(opts?: HandlerOptions): (req: Request) => Promise<Response>;
|