@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,175 @@
1
+ /**
2
+ * `<ComputerView>`'s connection to the agent's browser, without React or the DOM: the view stream, Take over, input
3
+ * and Give back.
4
+ *
5
+ * - THE HOST MINTS, the component asks. `fetchViewer({control: false})` on open and on every reconnect (a view token
6
+ * opens one stream, once); `fetchViewer({control: true})` only when a person presses Take over, so no control token
7
+ * exists until someone asks for one.
8
+ * - TOKENS ARE IN MEMORY ONLY: in `Authorization`, and the stream's channel in `ol-view-channel`; never in a URL, the
9
+ * snapshot a view draws from, an error's text or a callback.
10
+ * - THE STREAM IS READ WITH `fetch` (never an `EventSource`, which would put the token in the URL).
11
+ * - A DROP reconnects with a fresh view grant, three times, then says the browser can't be reached. A drop while the
12
+ * person held control says control went back (the kernel releases a channel's control when its stream closes).
13
+ * - THE END (a final `state {ended: true}`, or a 404/410 on the view) closes everything and never reconnects.
14
+ * - KEYS ARE NEVER LOST SILENTLY. Input goes one request at a time, in order. Give back and `stop()` send what was
15
+ * typed first and only then release: while batches keep being answered, until one goes unanswered for
16
+ * `drainStallMs` or `drainCapMs` has passed in all; then they release anyway, and say so. A batch is
17
+ * sent again only where the kernel's answer proves nothing of it was applied: every refusal of `/input` comes before
18
+ * the kernel applies anything, so a 401 or 403 (its token) is sent once more, after a fresh control grant and a
19
+ * re-take on the same stream. A 5xx can fail partway and an answer that never came proves nothing, so those are never
20
+ * sent again (a key typed twice is as wrong as one lost): control goes back and the note says the last keys may not
21
+ * have landed (`lost`). A 200 says how many it applied; fewer than sent means control or the session ended.
22
+ */
23
+ import { type ViewerInput } from "./computer-wire.ts";
24
+ /** What the host's server answers for `POST /computer_sessions/{id}/viewer`, as the kit needs it. */
25
+ export interface ViewerGrant {
26
+ /** The kernel's session base (`…/v1/sessions/:sid`); the component appends `/view`, `/control` and `/input`. */
27
+ url: string;
28
+ token: string;
29
+ /** When the token stops working: an ISO time, ms since the epoch, or a Date. */
30
+ expiresAt: string | number | Date;
31
+ }
32
+ /**
33
+ * The host's function: it asks its own server, which calls the platform's viewer route with ITS registered origin.
34
+ * `session` is the `cps_…` the view is for (null when the view was given none: your function knows it). Throw
35
+ * `ComputerViewRefused` for a refusal (the person may not watch or take over), with the words to show; any other throw
36
+ * is a failure the component retries. `readViewerGrant` turns your route's `Response` into either.
37
+ */
38
+ export type FetchViewer = (req: {
39
+ session: string | null;
40
+ control: boolean;
41
+ signal: AbortSignal;
42
+ }) => Promise<ViewerGrant>;
43
+ /** What the connection asks for: `FetchViewer` with the session already chosen. */
44
+ export type MintViewer = (req: {
45
+ control: boolean;
46
+ signal: AbortSignal;
47
+ }) => Promise<ViewerGrant>;
48
+ /** A refusal from the host's server, in its own words (shown as text), or none (the kit's sentence). */
49
+ export declare class ComputerViewRefused extends Error {
50
+ readonly said: string | null;
51
+ /** The host may say yes later (its route answered 429): the view offers Try again. */
52
+ readonly retry: boolean;
53
+ /**
54
+ * The browser's state changed while the grant was being made (the platform answered 409), so no token was made and
55
+ * asking again at once may work: the view asks once more, quietly, after a short wait.
56
+ */
57
+ readonly conflict: boolean;
58
+ constructor(said: string | null, options?: {
59
+ retry?: boolean;
60
+ conflict?: boolean;
61
+ });
62
+ }
63
+ /**
64
+ * Your route's answer as a grant: the platform's `computer_viewer` object passed through (`{url, token, expires_at}`),
65
+ * or a refusal. A 4xx is `ComputerViewRefused` with its `error.message` (at most 500 characters); a 5xx or a malformed
66
+ * answer is an `Error` the component retries. A 409 (the browser's state changed while the grant was being made) is a
67
+ * `conflict`: the view asks once more by itself, and offers Try again if that meets one too.
68
+ */
69
+ export declare function readViewerGrant(res: Response): Promise<ViewerGrant>;
70
+ /**
71
+ * Why a person's control ended, or what their last press did; it holds until the next press. `lost`: keys the person
72
+ * typed may not have reached the page (a batch the kernel did not take, or keys still queued when control ended).
73
+ */
74
+ export type ViewerNote = {
75
+ kind: "gave_back";
76
+ lost?: true;
77
+ } | {
78
+ kind: "expired";
79
+ lost?: true;
80
+ } | {
81
+ kind: "dropped";
82
+ lost?: true;
83
+ } | {
84
+ kind: "take_refused";
85
+ said: string | null;
86
+ };
87
+ /** What a view draws from. No token and no channel are ever in it. */
88
+ export interface ViewerSnapshot {
89
+ phase: "connecting" | "live" | "reconnecting" | "unreachable" | "refused" | "ended";
90
+ /** The page's host, checked as a hostname; null when the kernel sent none or one that is not. */
91
+ host: string | null;
92
+ /** Who holds the browser: this person, someone else (another window, another viewer), or nobody (the agent). */
93
+ control: "you" | "other" | null;
94
+ /** The stream gave a channel, so Take over can work. */
95
+ canTake: boolean;
96
+ /** A Take over or Give back is on its way. */
97
+ taking: boolean;
98
+ note: ViewerNote | null;
99
+ /** The person's control ends within `soonMs`. */
100
+ soon: boolean;
101
+ /** The current picture only; the one before it is gone. */
102
+ frame: {
103
+ blob: Blob;
104
+ w: number;
105
+ h: number;
106
+ seq: number;
107
+ } | null;
108
+ /** `refused`: the host's words, or null for the kit's sentence. */
109
+ said: string | null;
110
+ /** `unreachable` (and a refused that may be tried again): Try again starts over. */
111
+ retry: boolean;
112
+ }
113
+ export interface ComputerViewerOptions {
114
+ fetchViewer: MintViewer;
115
+ /** For the kernel's routes; the page's own `fetch` by default. */
116
+ fetch?: typeof fetch | undefined;
117
+ onChange: (snapshot: ViewerSnapshot) => void;
118
+ /** Waits before each reconnect, ms; their count is how many reconnects before "can't be reached". */
119
+ retryDelays?: readonly number[];
120
+ /** How long before control runs out the person is told, ms. */
121
+ soonMs?: number;
122
+ /**
123
+ * How long a connection may take, from asking for a view grant to the stream's first `frame` (a new stream gets the
124
+ * current frame at once, after its first `state`), ms. Past it, the attempt is a drop: the reconnects, then
125
+ * "can't be reached" with Try again.
126
+ */
127
+ firstFrameMs?: number;
128
+ /**
129
+ * A live stream with no bytes at all for this long, ms, is a drop. The kernel writes a keep-alive comment at least
130
+ * every 15 s, so three missed ones (45 s) mean the connection is gone, even when the page has nothing new to show.
131
+ */
132
+ silenceMs?: number;
133
+ /** Each step of a connection as it happens, for diagnosing a stall: a step's name and the time, nothing else. */
134
+ onTiming?: ((step: ViewerTimingStep, at: number) => void) | undefined;
135
+ now?: () => number;
136
+ /** Give back and `stop()` keep sending what was typed while batches are answered; one unanswered this long ends it, ms. */
137
+ drainStallMs?: number;
138
+ /** However the batches move, Give back and `stop()` release after this long, ms. */
139
+ drainCapMs?: number;
140
+ }
141
+ /**
142
+ * A connection's steps, in order; `watchdog` when no first frame came in time, `silence` when a live stream carried
143
+ * no bytes for too long; `first_picture` is the view's own.
144
+ */
145
+ export type ViewerTimingStep = "view_asked" | "view_granted" | "stream_opened" | "first_bytes" | "first_state" | "first_frame" | "watchdog" | "silence" | "first_picture" | InputFailureStep;
146
+ /**
147
+ * Why keys did not all land, one step each: the kernel took only part of a batch (`input_partial`), refused its token
148
+ * (`input_token`, then one fresh grant and one resend), said another viewer holds control (`input_conflict`), said the
149
+ * session is gone (`input_gone`), refused the batch (`input_refused`), failed it (`input_failed`, a 5xx), or the
150
+ * answer never came (`input_network`); or control ended with keys still queued (`input_unsent`).
151
+ */
152
+ type InputFailureStep = "input_partial" | "input_token" | "input_conflict" | "input_gone" | "input_refused" | "input_failed" | "input_network" | "input_unsent";
153
+ export interface ComputerViewer {
154
+ start(): void;
155
+ /** Close the stream; keys already typed are sent, then control the person holds is given back, then it closes. */
156
+ stop(): void;
157
+ take(): Promise<void>;
158
+ giveBack(): Promise<void>;
159
+ /** Input while the person holds control; anything else is dropped. Sent in order, at most 64 a request. */
160
+ send(events: readonly ViewerInput[]): void;
161
+ /** Try again after "can't be reached". */
162
+ retry(): void;
163
+ snapshot(): ViewerSnapshot;
164
+ }
165
+ export declare const RETRY_DELAYS_MS: readonly [1000, 3000, 9000];
166
+ export declare const CONTROL_SOON_MS = 120000;
167
+ export declare const FIRST_FRAME_MS = 15000;
168
+ /** Give back and `stop()` give up on what was typed when one batch has gone unanswered this long, ms. */
169
+ export declare const DRAIN_STALL_MS = 8000;
170
+ /** However the batches move, Give back and `stop()` release after this long, ms: nobody is held for long. */
171
+ export declare const DRAIN_CAP_MS = 20000;
172
+ /** How long the view waits before it asks once more for a grant the platform answered 409, ms. */
173
+ export declare const CONFLICT_RETRY_MS = 500;
174
+ export declare function createComputerViewer(opts: ComputerViewerOptions): ComputerViewer;
175
+ export {};