@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
package/dist/errors.js ADDED
@@ -0,0 +1,134 @@
1
+ const LIMIT_CAPS = new Set(["daily", "period", "agent_daily"]);
2
+ const RFC3339 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/;
3
+ export function errorLimitOf(raw) {
4
+ if (!raw || typeof raw !== "object" || Array.isArray(raw))
5
+ return null;
6
+ const o = raw;
7
+ const cap = o["cap"];
8
+ const why = o["why"];
9
+ const at = o["resets_at"];
10
+ if (typeof cap !== "string" || !LIMIT_CAPS.has(cap) || (why !== "used_up" && why !== "too_small"))
11
+ return null;
12
+ if (at !== null && (typeof at !== "string" || !RFC3339.test(at) || Number.isNaN(Date.parse(at))))
13
+ return null;
14
+ return { cap: cap, why, resets_at: at };
15
+ }
16
+ export class OpenLegionError extends Error {
17
+ name = "OpenLegionError";
18
+ type;
19
+ code;
20
+ param;
21
+ partner_message;
22
+ limit;
23
+ doc_url;
24
+ request_id;
25
+ status;
26
+ headers;
27
+ constructor(init) {
28
+ super(init.message, init.cause === undefined ? undefined : { cause: init.cause });
29
+ this.type = init.type;
30
+ this.code = init.code;
31
+ this.param = init.param ?? null;
32
+ this.partner_message = init.partner_message ?? null;
33
+ this.limit = init.limit ?? null;
34
+ this.doc_url = init.doc_url ?? null;
35
+ this.request_id = init.request_id ?? null;
36
+ this.status = init.status ?? null;
37
+ this.headers = init.headers ?? null;
38
+ }
39
+ }
40
+ export class InvalidRequestError extends OpenLegionError {
41
+ name = "InvalidRequestError";
42
+ }
43
+ export class AuthenticationError extends OpenLegionError {
44
+ name = "AuthenticationError";
45
+ }
46
+ export class PermissionError extends OpenLegionError {
47
+ name = "PermissionError";
48
+ }
49
+ export class NotFoundError extends OpenLegionError {
50
+ name = "NotFoundError";
51
+ }
52
+ export class ConflictError extends OpenLegionError {
53
+ name = "ConflictError";
54
+ }
55
+ export class RefusalError extends OpenLegionError {
56
+ name = "RefusalError";
57
+ }
58
+ export class RateLimitError extends OpenLegionError {
59
+ name = "RateLimitError";
60
+ get retryAfterSeconds() {
61
+ const ms = retryAfterMs(this.headers);
62
+ return ms === null ? null : Math.ceil(ms / 1000);
63
+ }
64
+ }
65
+ export class APIError extends OpenLegionError {
66
+ name = "APIError";
67
+ }
68
+ export class APIConnectionError extends OpenLegionError {
69
+ name = "APIConnectionError";
70
+ }
71
+ export class SignatureVerificationError extends OpenLegionError {
72
+ name = "SignatureVerificationError";
73
+ reason;
74
+ constructor(reason, message) {
75
+ super({ type: "signature_verification_error", code: reason, message });
76
+ this.reason = reason;
77
+ }
78
+ }
79
+ const BY_TYPE = {
80
+ invalid_request_error: InvalidRequestError,
81
+ authentication_error: AuthenticationError,
82
+ permission_error: PermissionError,
83
+ not_found_error: NotFoundError,
84
+ conflict_error: ConflictError,
85
+ refusal: RefusalError,
86
+ rate_limit_error: RateLimitError,
87
+ api_error: APIError,
88
+ };
89
+ const str = (v) => (typeof v === "string" ? v : null);
90
+ export function errorFromResponse(status, headers, text) {
91
+ const requestId = headers.get("request-id");
92
+ let envelope = null;
93
+ try {
94
+ const parsed = JSON.parse(text);
95
+ const e = typeof parsed === "object" && parsed !== null ? parsed["error"] : null;
96
+ if (typeof e === "object" && e !== null)
97
+ envelope = e;
98
+ }
99
+ catch {
100
+ envelope = null;
101
+ }
102
+ if (!envelope || typeof envelope["type"] !== "string" || !BY_TYPE[envelope["type"]]) {
103
+ return new APIError({
104
+ type: "api_error",
105
+ code: "unexpected_response",
106
+ message: `OpenLegion answered HTTP ${status} without an error envelope.`,
107
+ request_id: requestId,
108
+ status,
109
+ headers,
110
+ });
111
+ }
112
+ const Cls = BY_TYPE[envelope["type"]];
113
+ return new Cls({
114
+ type: envelope["type"],
115
+ code: str(envelope["code"]) ?? "unknown",
116
+ message: str(envelope["message"]) ?? `HTTP ${status}`,
117
+ param: str(envelope["param"]),
118
+ partner_message: str(envelope["partner_message"]),
119
+ limit: errorLimitOf(envelope["limit"]),
120
+ doc_url: str(envelope["doc_url"]),
121
+ request_id: str(envelope["request_id"]) ?? requestId,
122
+ status,
123
+ headers,
124
+ });
125
+ }
126
+ export function retryAfterMs(headers, now = Date.now()) {
127
+ const raw = headers?.get("retry-after");
128
+ if (!raw)
129
+ return null;
130
+ if (/^\d+$/.test(raw.trim()))
131
+ return Number(raw.trim()) * 1000;
132
+ const at = Date.parse(raw);
133
+ return Number.isNaN(at) ? null : Math.max(0, at - now);
134
+ }
@@ -0,0 +1,131 @@
1
+ /**
2
+ * The typed event: what `data.object` is for each event type.
3
+ *
4
+ * `EventObjects` is checked against the generated `EventType` both ways, so an event type added to the
5
+ * API fails this package's typecheck until it is mapped here. The money events' objects are OpenAPI
6
+ * components (`UsageAlert`, `BalanceNotice`, …); `org.statement.closed`'s statement has no schema yet, so it
7
+ * is `Record<string, unknown>`.
8
+ */
9
+ import type { Action, Agent, Approval, AutoReloadNotice, BalanceNotice, BillingAccountNotice, Connection, EventType, Message, PlatformEvent, Run, Task, Template, TopupNotice, TopupReversal, UsageAlert, Workspace, WorkspacesDeleteResponse } from "./generated/api.ts";
10
+ type Untyped = Record<string, unknown>;
11
+ /** export.ready / export.failed carry a short form of the export, never its link. */
12
+ export interface ExportNotice {
13
+ object: "export";
14
+ id: string;
15
+ workspace?: string;
16
+ size_bytes?: number;
17
+ expires_at?: string;
18
+ failure_code?: string;
19
+ }
20
+ /** connector.drifted: the connector, and the tools flagged or disabled (in `data.flagged` / `data.disabled`). */
21
+ export interface ConnectorRef {
22
+ object: "connector";
23
+ id: string;
24
+ name: string;
25
+ slug: string;
26
+ }
27
+ /** computer.session_ended: the agent's browser as the conversation's `data-computer` part draws it, ended. */
28
+ export interface ComputerSessionNotice {
29
+ object: "computer_session";
30
+ /** `cps_…`. */
31
+ id: string;
32
+ /** `agt_…`. */
33
+ agent: string;
34
+ /** The host the browser was last on; null before any page. */
35
+ site: string | null;
36
+ status: "ended";
37
+ reason: "run_ended" | "closed" | "deadline" | "park_expired" | "stopped" | "failed";
38
+ }
39
+ /** `data.object` per event type. */
40
+ export interface EventObjects {
41
+ "run.completed": Run;
42
+ "run.failed": Run;
43
+ "run.cancelled": Run;
44
+ "action.requires_approval": Action;
45
+ "action.completed": Action;
46
+ "action.failed": Action;
47
+ "approval.requested": Approval;
48
+ "approval.decided": Approval;
49
+ "approval.expired": Approval;
50
+ "message.created": Message;
51
+ "agent.paused": Agent;
52
+ "agent.resumed": Agent;
53
+ "agent.attention_needed": Message;
54
+ "task.completed": Task;
55
+ "task.failed": Task;
56
+ "task.escalated": Task;
57
+ "schedule.missed": Agent;
58
+ "workspace.cap_reached": UsageAlert;
59
+ "usage.threshold_reached": UsageAlert;
60
+ "org.credits.low": BalanceNotice;
61
+ "org.credits.exhausted": BalanceNotice;
62
+ "org.topup.reversed": TopupReversal;
63
+ "org.statement.closed": Untyped;
64
+ "org.billing_account.changed": BillingAccountNotice;
65
+ "org.credits.reloaded": AutoReloadNotice;
66
+ "org.credits.reload_failed": AutoReloadNotice;
67
+ "org.credits.buffer_used": BalanceNotice;
68
+ "org.topup.failed": TopupNotice;
69
+ "connector.drifted": ConnectorRef;
70
+ "workspace.suspended": Workspace;
71
+ "workspace.resumed": Workspace;
72
+ "workspace.archived": Workspace;
73
+ "workspace.restored": Workspace;
74
+ "workspace.erased": WorkspacesDeleteResponse;
75
+ "export.ready": ExportNotice;
76
+ "export.failed": ExportNotice;
77
+ "template.promoted": Template;
78
+ "connection.created": Connection;
79
+ "connection.updated": Connection;
80
+ "connection.needs_reauth": Connection;
81
+ "connection.revoked": Connection;
82
+ "computer.session_ended": ComputerSessionNotice;
83
+ ping: {
84
+ object: "webhook_endpoint";
85
+ id: string;
86
+ };
87
+ }
88
+ /**
89
+ * The keys an event's `data` carries beside `object`, by type. They are there on a truncated event too.
90
+ * - `action.requires_approval`: `approval`, the `apr_…` to decide (`ol.workspace(ws).approvals.decide`).
91
+ * A held tool call announces THIS type, not `approval.requested`, which is the agent's own question.
92
+ * - `schedule.missed`: why, and the day it was due (`YYYY-MM-DD`).
93
+ * - `computer.session_ended`: the session's id, its agent, the run that opened it (null when none you see), why it
94
+ * ended, and how many seconds it was in use.
95
+ */
96
+ export interface EventExtras {
97
+ "action.requires_approval": {
98
+ approval: string;
99
+ };
100
+ "schedule.missed": {
101
+ reason: string | null;
102
+ day: string | null;
103
+ };
104
+ "computer.session_ended": {
105
+ session: string;
106
+ agent: string;
107
+ run: string | null;
108
+ reason: ComputerSessionNotice["reason"];
109
+ active_seconds: number;
110
+ };
111
+ }
112
+ type ExtrasOf<T extends EventType> = T extends keyof EventExtras ? EventExtras[T] : unknown;
113
+ /** A webhook (or `GET /events` item) whose `data.object` is typed by its `type`. */
114
+ export type WebhookEvent<T extends EventType = EventType> = T extends EventType ? Omit<PlatformEvent, "type" | "data"> & {
115
+ type: T;
116
+ data: ({
117
+ object: EventObjects[T] | null;
118
+ truncated?: false;
119
+ [key: string]: unknown;
120
+ } & ExtrasOf<T>)
121
+ /** Too large to carry: fetch the object by its id. The keys beside it (`EventExtras`) are still here. */
122
+ | ({
123
+ object: {
124
+ object: string | null;
125
+ id: string | null;
126
+ };
127
+ truncated: true;
128
+ [key: string]: unknown;
129
+ } & ExtrasOf<T>);
130
+ } : never;
131
+ export {};
package/dist/events.js ADDED
@@ -0,0 +1,5 @@
1
+ const mapped = true;
2
+ void mapped;
3
+ const extrasMapped = true;
4
+ void extrasMapped;
5
+ export {};