@openartifactsai/runtime 0.0.0-stage → 0.23.0-rc.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/NOTICE +5 -0
- package/README.md +5 -2
- package/package.json +64 -4
- package/src/broker.d.ts +93 -0
- package/src/broker.js +442 -0
- package/src/capabilities.d.ts +915 -0
- package/src/capabilities.js +77 -0
- package/src/client.d.ts +33 -0
- package/src/client.js +76 -0
- package/src/doc-api.d.ts +280 -0
- package/src/doc-api.js +35 -0
- package/src/http-api.d.ts +373 -0
- package/src/http-api.js +72 -0
- package/src/index.d.ts +24 -0
- package/src/index.js +24 -0
- package/src/legacy-storage.d.ts +1 -0
- package/src/legacy-storage.js +7 -0
- package/src/local-provider.d.ts +44 -0
- package/src/local-provider.js +491 -0
- package/src/roles.d.ts +41 -0
- package/src/roles.js +47 -0
- package/src/sample.d.ts +92 -0
- package/src/sample.js +570 -0
- package/src/sheet-api.d.ts +426 -0
- package/src/sheet-api.js +35 -0
- package/src/shell.d.ts +73 -0
- package/src/shell.js +197 -0
- package/src/untrusted.d.ts +24 -0
- package/src/untrusted.js +35 -0
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract between a Sheets page and its server (the `sheet` capability).
|
|
3
|
+
*
|
|
4
|
+
* The workbook is an edit log: revision n is the workbook after the first n
|
|
5
|
+
* edits, each a list of engine operations written in a format version `v`
|
|
6
|
+
* and made on revision `base`. A page keeps its own engine session in step
|
|
7
|
+
* with the log: it reads a snapshot and loads the operations, hears every
|
|
8
|
+
* later edit on the `sheet` event of `_api/events`, and sends its own edits
|
|
9
|
+
* to `send`. Every new event connection gets a snapshot frame first, so a
|
|
10
|
+
* page that reconnects learns how far the log moved meanwhile.
|
|
11
|
+
*
|
|
12
|
+
* Every route is relative to the artifact's page base, as the runtime's
|
|
13
|
+
* `API` routes are.
|
|
14
|
+
*/
|
|
15
|
+
export type Json = null | boolean | number | string | Json[] | {
|
|
16
|
+
[key: string]: Json;
|
|
17
|
+
};
|
|
18
|
+
export type JsonObject = {
|
|
19
|
+
[key: string]: Json;
|
|
20
|
+
};
|
|
21
|
+
/** Route paths, relative to the page base. */
|
|
22
|
+
export declare const SHEET_API: {
|
|
23
|
+
/** `POST` {@link SheetReadRequest} → the read's answer. */
|
|
24
|
+
readonly read: "_api/sheet/read";
|
|
25
|
+
/** `POST` {@link SheetSendRequest} → {@link SheetSendResponse}. */
|
|
26
|
+
readonly send: "_api/sheet/send";
|
|
27
|
+
/** `POST` {@link WidgetRequest} → {@link WidgetResponse}. */
|
|
28
|
+
readonly widget: "_api/sheet/widget";
|
|
29
|
+
/** `POST` a file's bytes (`?name=`), kept for the agent to import → {@link ImportFileResponse}. */
|
|
30
|
+
readonly importFile: "_api/sheet/import";
|
|
31
|
+
};
|
|
32
|
+
/** The server-sent event name the frames arrive under on `_api/events`. */
|
|
33
|
+
export declare const SHEET_EVENT = "sheet";
|
|
34
|
+
/**
|
|
35
|
+
* The server-sent event a walkthrough arrives under on `_api/events`. The agent sends one with the read
|
|
36
|
+
* `{"kind": "showGuide", "guide": {"stops": […]}}`; the server gives it to one page of the owner's, the one they used
|
|
37
|
+
* last, and to no one else.
|
|
38
|
+
*/
|
|
39
|
+
export declare const SHEET_WALKTHROUGH_EVENT = "sheetWalkthrough";
|
|
40
|
+
/**
|
|
41
|
+
* One stop of a walkthrough: `at` is a cell link, the part of the page's address after `#` (`sheet-<sheetId>~A2-D2~B1`,
|
|
42
|
+
* the `#` may lead), and `say` is plain text, what the page shows beside those cells.
|
|
43
|
+
*/
|
|
44
|
+
export type WalkthroughStop = {
|
|
45
|
+
at: string;
|
|
46
|
+
say: string;
|
|
47
|
+
};
|
|
48
|
+
/** A walkthrough: 1 to 30 stops, which the page steps the person through in order. A new one replaces the last. */
|
|
49
|
+
export type SheetWalkthrough = {
|
|
50
|
+
stops: WalkthroughStop[];
|
|
51
|
+
};
|
|
52
|
+
/** Who made an edit, as pages show them. */
|
|
53
|
+
export type EditActor = {
|
|
54
|
+
/** The id the engine knows the person by (`u_` and 22 letters and digits). */
|
|
55
|
+
personId: string;
|
|
56
|
+
/** True for the agent's edits (made for the owner). */
|
|
57
|
+
isAgent: boolean;
|
|
58
|
+
};
|
|
59
|
+
/** A person as the page names them in cells (people chips) and history. */
|
|
60
|
+
export type SheetPerson = {
|
|
61
|
+
personId: string;
|
|
62
|
+
name: string;
|
|
63
|
+
/** Present only for the owner and the people viewing now. */
|
|
64
|
+
color?: string;
|
|
65
|
+
};
|
|
66
|
+
/** The first frame of a stream: where the log stands and who the page's person is. */
|
|
67
|
+
export type SnapshotFrame = {
|
|
68
|
+
phase: 'snapshot';
|
|
69
|
+
/** The workbook's id (a UUID). */
|
|
70
|
+
workbookId: string;
|
|
71
|
+
/** When the workbook was made, ISO 8601. */
|
|
72
|
+
createdAt: string;
|
|
73
|
+
revision: number;
|
|
74
|
+
/** The newest format version the server takes. */
|
|
75
|
+
newestFormatVersion: number;
|
|
76
|
+
widgets: WidgetVersion[];
|
|
77
|
+
/** The page's person: the id the engine knows them by, whether they may edit, and whether they own the workbook (protections never hold against the owner). */
|
|
78
|
+
viewer: {
|
|
79
|
+
personId: string;
|
|
80
|
+
canEdit: boolean;
|
|
81
|
+
isOwner: boolean;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* True when this page may ask for a connected table's rows to be fetched again ({@link SheetRefreshRequest}): only
|
|
85
|
+
* the owner's pages, and only while the agent can be reached.
|
|
86
|
+
*/
|
|
87
|
+
takesConnectedTables?: boolean;
|
|
88
|
+
};
|
|
89
|
+
/** An edit saved to the log (anyone's, the page's own among them). */
|
|
90
|
+
export interface EditFrame {
|
|
91
|
+
phase: 'edit';
|
|
92
|
+
revision: number;
|
|
93
|
+
v: number;
|
|
94
|
+
base: number;
|
|
95
|
+
ops: Json[];
|
|
96
|
+
actor: EditActor;
|
|
97
|
+
}
|
|
98
|
+
/** The clock, for `NOW()` and `TODAY()`: sent at the start, each minute and when the workbook's time zone changes. */
|
|
99
|
+
export interface ClockFrame {
|
|
100
|
+
phase: 'clock';
|
|
101
|
+
unixMilliseconds: number;
|
|
102
|
+
utcOffsetInMinutes: number;
|
|
103
|
+
timeZone: string | null;
|
|
104
|
+
}
|
|
105
|
+
/** A widget's code was published (its charts draw it again). */
|
|
106
|
+
export interface WidgetFrame {
|
|
107
|
+
phase: 'widget';
|
|
108
|
+
id: string;
|
|
109
|
+
pub: number;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* How a refresh of a connected table ended without new rows, sent to the owner's pages. Rows that arrive come as an
|
|
113
|
+
* ordinary edit (a new snapshot of the sheet), so a refresh that worked sends no frame of its own.
|
|
114
|
+
*/
|
|
115
|
+
export interface TableRefreshFrame {
|
|
116
|
+
phase: 'tableRefresh';
|
|
117
|
+
sheetId: string;
|
|
118
|
+
/** The call the refresh was asked for. */
|
|
119
|
+
callDigest: string;
|
|
120
|
+
outcome: {
|
|
121
|
+
state: 'refused';
|
|
122
|
+
why: string;
|
|
123
|
+
toolSaid?: string;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export type SheetFrame = SnapshotFrame | EditFrame | ClockFrame | WidgetFrame | TableRefreshFrame;
|
|
127
|
+
/** A widget and its published version. */
|
|
128
|
+
export type WidgetVersion = {
|
|
129
|
+
id: string;
|
|
130
|
+
pub: number;
|
|
131
|
+
};
|
|
132
|
+
/** `POST send`: one of the page's edits, as the engine recorded it. */
|
|
133
|
+
export interface SheetOpsRequest {
|
|
134
|
+
opId: string;
|
|
135
|
+
v: number;
|
|
136
|
+
base: number;
|
|
137
|
+
ops: Json[];
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* `POST send`: edits a page asks the server to make on revision `base`, as the agent's are (a new workbook's first
|
|
141
|
+
* sheet, its locale).
|
|
142
|
+
*/
|
|
143
|
+
export interface SheetEditsRequest {
|
|
144
|
+
opId: string;
|
|
145
|
+
base: number;
|
|
146
|
+
edits: JsonObject[];
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* `POST send`: names the version that ends at `revision` in the history pane, or takes its name away (`name` empty).
|
|
150
|
+
* The log does not move. Line breaks and runs of spaces in the name become one space; at most
|
|
151
|
+
* {@link MOST_VERSION_NAME_LENGTH} characters, and at most {@link MOST_VERSION_NAMES} named versions.
|
|
152
|
+
*/
|
|
153
|
+
export interface SheetVersionNameRequest {
|
|
154
|
+
kind: 'setVersionName';
|
|
155
|
+
revision: number;
|
|
156
|
+
name: string;
|
|
157
|
+
}
|
|
158
|
+
export declare const MOST_VERSION_NAMES = 100;
|
|
159
|
+
export declare const MOST_VERSION_NAME_LENGTH = 100;
|
|
160
|
+
/**
|
|
161
|
+
* `POST send`: asks for a connected table's rows to be fetched again with its call as it stands (`callDigest`, as the
|
|
162
|
+
* engine reads it). The server hands the call to the agent and answers at once with `refreshAsked`; the rows arrive
|
|
163
|
+
* later as an edit, or a {@link TableRefreshFrame} tells why they did not. Only the owner may ask.
|
|
164
|
+
*/
|
|
165
|
+
export interface SheetRefreshRequest {
|
|
166
|
+
kind: 'refreshConnectedTable';
|
|
167
|
+
sheetId: string;
|
|
168
|
+
callDigest: string;
|
|
169
|
+
}
|
|
170
|
+
export type SheetSendRequest = SheetOpsRequest | SheetEditsRequest | SheetVersionNameRequest | SheetRefreshRequest;
|
|
171
|
+
export type SheetSendResponse = {
|
|
172
|
+
kind: 'saved';
|
|
173
|
+
revision: number;
|
|
174
|
+
}
|
|
175
|
+
/** The answer to a {@link SheetVersionNameRequest}: the name as kept (null once taken away). */
|
|
176
|
+
| {
|
|
177
|
+
kind: 'versionNamed';
|
|
178
|
+
revision: number;
|
|
179
|
+
name: string | null;
|
|
180
|
+
}
|
|
181
|
+
/** The answer to a {@link SheetRefreshRequest}: the agent was asked to fetch the rows. */
|
|
182
|
+
| {
|
|
183
|
+
kind: 'refreshAsked';
|
|
184
|
+
}
|
|
185
|
+
/** `revision` is where the log stands, for an edits request whose base it is not. */
|
|
186
|
+
| {
|
|
187
|
+
kind: 'refused';
|
|
188
|
+
refusal: SendRefusal;
|
|
189
|
+
revision?: number;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Why a save is refused: the engine's refusal, or one of the store's own.
|
|
193
|
+
* `changedSince` means the edit no longer applies on the edits made since its base.
|
|
194
|
+
*/
|
|
195
|
+
export type SendRefusal = 'changedSince' | 'pageIsBehind' | 'unknownFormatVersion' | 'unreadableEdit' | 'tooLarge' | 'notWriter'
|
|
196
|
+
/** Naming a version: the name is not text, the revision is not one of the log's, the name is too long, or a new name would be one too many. */
|
|
197
|
+
| 'unreadableVersionName' | 'unknownRevision' | 'versionNameNotAllowed' | 'tooManyVersionNames'
|
|
198
|
+
/**
|
|
199
|
+
* Refreshing a connected table: the page's person is not the owner, the sheet is not a connected table, its call
|
|
200
|
+
* is no longer `callDigest`, the agent cannot be reached, or a refresh of it is already under way.
|
|
201
|
+
*/
|
|
202
|
+
| 'notOwner' | 'notAConnectedTable' | 'callChanged' | 'agentNotListening' | 'refreshUnderWay' | (string & {});
|
|
203
|
+
/** The workbook's operations from a revision on, one page: the page has its engine write them as the lines it loads. */
|
|
204
|
+
export type LoadPage = {
|
|
205
|
+
kind: 'loadPage';
|
|
206
|
+
from: number;
|
|
207
|
+
revision: number;
|
|
208
|
+
v: number;
|
|
209
|
+
ops: Json[];
|
|
210
|
+
next: number | null;
|
|
211
|
+
};
|
|
212
|
+
/** A version of the history pane: the edits from `firstRevision` to `revision`, newest first. */
|
|
213
|
+
export type VersionRow = {
|
|
214
|
+
revision: number;
|
|
215
|
+
firstRevision: number;
|
|
216
|
+
/** Where its first edit stands in the log: a page of versions asked for `beforeSeq` ends before it. */
|
|
217
|
+
firstSeq: number;
|
|
218
|
+
/** When its last edit was made, ISO 8601. */
|
|
219
|
+
at: string;
|
|
220
|
+
authors: EditActor[];
|
|
221
|
+
/** The name it was given in the history pane; a named version ends there, the edits after it start the next one. */
|
|
222
|
+
name?: string;
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* A version with what its edits did, for the one-line summary the history pane may ask the agent for: `acts` counts
|
|
226
|
+
* each kind of operation by sheet (a setCells by its cells), at most 40 of them, `areActsLeftOut` telling of more.
|
|
227
|
+
*/
|
|
228
|
+
export type VersionRowWithChanges = VersionRow & {
|
|
229
|
+
content: {
|
|
230
|
+
acts: {
|
|
231
|
+
kind: string;
|
|
232
|
+
sheet?: string;
|
|
233
|
+
count: number;
|
|
234
|
+
}[];
|
|
235
|
+
areActsLeftOut?: true;
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
/** Edits a page saves as one edit to take others back (restoring a version, undoing an agent's turn). */
|
|
239
|
+
export type EditsToTakeBack = {
|
|
240
|
+
kind: 'editsToTakeBack';
|
|
241
|
+
revision: number;
|
|
242
|
+
edits: JsonObject[];
|
|
243
|
+
};
|
|
244
|
+
/** What a cell or a row held after an edit that changed it, newest first. */
|
|
245
|
+
export type CellHistoryRow = {
|
|
246
|
+
revision: number;
|
|
247
|
+
at: string;
|
|
248
|
+
actor: EditActor;
|
|
249
|
+
[held: string]: Json | EditActor;
|
|
250
|
+
};
|
|
251
|
+
export type CellHistory = {
|
|
252
|
+
kind: 'cellHistory';
|
|
253
|
+
rows: CellHistoryRow[];
|
|
254
|
+
/** Earlier changes were left out. */
|
|
255
|
+
truncated: boolean;
|
|
256
|
+
};
|
|
257
|
+
/** A revision range of edits, both ends included. */
|
|
258
|
+
export interface RevisionRange {
|
|
259
|
+
first: number;
|
|
260
|
+
last: number;
|
|
261
|
+
}
|
|
262
|
+
/** `POST read`: what the page asks the server. */
|
|
263
|
+
export type SheetReadRequest = {
|
|
264
|
+
kind: 'snapshot';
|
|
265
|
+
} | {
|
|
266
|
+
kind: 'load';
|
|
267
|
+
from?: number;
|
|
268
|
+
} | {
|
|
269
|
+
kind: 'loadAtRevision';
|
|
270
|
+
revision: number;
|
|
271
|
+
} | {
|
|
272
|
+
kind: 'versions';
|
|
273
|
+
limit?: number;
|
|
274
|
+
before?: number;
|
|
275
|
+
beforeSeq?: number;
|
|
276
|
+
}
|
|
277
|
+
/** Every named version older than `before`, newest first. */
|
|
278
|
+
| {
|
|
279
|
+
kind: 'namedVersions';
|
|
280
|
+
before?: number;
|
|
281
|
+
beforeSeq?: number;
|
|
282
|
+
}
|
|
283
|
+
/** The same rows as `versions`: what a summary of each version would be written from. */
|
|
284
|
+
| {
|
|
285
|
+
kind: 'versionsWithChanges';
|
|
286
|
+
limit?: number;
|
|
287
|
+
before?: number;
|
|
288
|
+
beforeSeq?: number;
|
|
289
|
+
}
|
|
290
|
+
/** A slice of the file a connected table's snapshot keeps (`snapshotId`), from byte `from`. */
|
|
291
|
+
| {
|
|
292
|
+
kind: 'loadTableFile';
|
|
293
|
+
snapshotId: string;
|
|
294
|
+
from: number;
|
|
295
|
+
} | {
|
|
296
|
+
kind: 'editsThatRestore';
|
|
297
|
+
revision: number;
|
|
298
|
+
} | {
|
|
299
|
+
kind: 'editsThatUndo';
|
|
300
|
+
ranges: RevisionRange[];
|
|
301
|
+
} | {
|
|
302
|
+
kind: 'cellHistory';
|
|
303
|
+
sheetId: string;
|
|
304
|
+
r: string;
|
|
305
|
+
c: string;
|
|
306
|
+
} | {
|
|
307
|
+
kind: 'rowHistory';
|
|
308
|
+
sheetId: string;
|
|
309
|
+
r: string;
|
|
310
|
+
} | {
|
|
311
|
+
kind: 'people';
|
|
312
|
+
} | {
|
|
313
|
+
kind: 'sheets';
|
|
314
|
+
} | {
|
|
315
|
+
kind: 'xlsxCharts';
|
|
316
|
+
charts: JsonObject[];
|
|
317
|
+
};
|
|
318
|
+
/** The answers to {@link SheetReadRequest}, by kind. */
|
|
319
|
+
export interface SheetReadAnswers {
|
|
320
|
+
snapshot: SnapshotFrame;
|
|
321
|
+
load: LoadPage;
|
|
322
|
+
loadAtRevision: LoadPage;
|
|
323
|
+
versions: {
|
|
324
|
+
kind: 'versions';
|
|
325
|
+
rows: VersionRow[];
|
|
326
|
+
};
|
|
327
|
+
namedVersions: {
|
|
328
|
+
kind: 'namedVersions';
|
|
329
|
+
rows: VersionRow[];
|
|
330
|
+
};
|
|
331
|
+
versionsWithChanges: {
|
|
332
|
+
kind: 'versionsWithChanges';
|
|
333
|
+
rows: VersionRowWithChanges[];
|
|
334
|
+
};
|
|
335
|
+
loadTableFile: TableFileSlice;
|
|
336
|
+
editsThatRestore: EditsToTakeBack;
|
|
337
|
+
editsThatUndo: EditsToTakeBack;
|
|
338
|
+
cellHistory: CellHistory;
|
|
339
|
+
rowHistory: CellHistory;
|
|
340
|
+
people: {
|
|
341
|
+
kind: 'people';
|
|
342
|
+
people: SheetPerson[];
|
|
343
|
+
};
|
|
344
|
+
sheets: SheetsList;
|
|
345
|
+
xlsxCharts: {
|
|
346
|
+
kind: 'xlsxCharts';
|
|
347
|
+
descriptions: {
|
|
348
|
+
viewId: string;
|
|
349
|
+
description: JsonObject;
|
|
350
|
+
}[];
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* A slice of a connected table's file: `bytes` is base64 of the bytes from `from` on, of `byteCount` in all. The file
|
|
355
|
+
* is gzip; its lines are the table's rows by field. `body` names the file, the same for every slice of it. A file no
|
|
356
|
+
* longer kept (or never kept) is `isGone`.
|
|
357
|
+
*/
|
|
358
|
+
export type TableFileSlice = {
|
|
359
|
+
kind: 'tableFile';
|
|
360
|
+
body: string;
|
|
361
|
+
byteCount: number;
|
|
362
|
+
from: number;
|
|
363
|
+
bytes: string;
|
|
364
|
+
} | {
|
|
365
|
+
kind: 'tableFile';
|
|
366
|
+
isGone: true;
|
|
367
|
+
};
|
|
368
|
+
/** The workbook's sheets as the engine lists them (`readSheets`), with its locale. */
|
|
369
|
+
export type SheetsList = {
|
|
370
|
+
kind: 'sheets';
|
|
371
|
+
revision: number;
|
|
372
|
+
locale: string;
|
|
373
|
+
sheets: JsonObject[];
|
|
374
|
+
};
|
|
375
|
+
/** A read the server turned away. */
|
|
376
|
+
export type SheetReadRefusal = {
|
|
377
|
+
kind: 'refused';
|
|
378
|
+
refusal: string;
|
|
379
|
+
};
|
|
380
|
+
/** `POST widget`: a chart widget's node. */
|
|
381
|
+
export type WidgetRequest = {
|
|
382
|
+
verb: 'create';
|
|
383
|
+
opId: string;
|
|
384
|
+
code: string;
|
|
385
|
+
} | {
|
|
386
|
+
verb: 'read';
|
|
387
|
+
id: string;
|
|
388
|
+
} | {
|
|
389
|
+
verb: 'projection';
|
|
390
|
+
id: string;
|
|
391
|
+
} | {
|
|
392
|
+
verb: 'draft';
|
|
393
|
+
id: string;
|
|
394
|
+
basePub: number;
|
|
395
|
+
code: string;
|
|
396
|
+
} | {
|
|
397
|
+
verb: 'delete';
|
|
398
|
+
id: string;
|
|
399
|
+
};
|
|
400
|
+
export type WidgetState = {
|
|
401
|
+
id: string;
|
|
402
|
+
code: string;
|
|
403
|
+
pub: number;
|
|
404
|
+
/** Why the newest code is not published (it is staged), empty when it is. */
|
|
405
|
+
errors: string[];
|
|
406
|
+
};
|
|
407
|
+
export type WidgetResponse = {
|
|
408
|
+
kind: 'widget';
|
|
409
|
+
widget: WidgetState;
|
|
410
|
+
} | {
|
|
411
|
+
kind: 'projection';
|
|
412
|
+
id: string;
|
|
413
|
+
module: string;
|
|
414
|
+
} | {
|
|
415
|
+
kind: 'deleted';
|
|
416
|
+
} | {
|
|
417
|
+
kind: 'refused';
|
|
418
|
+
refusal: string;
|
|
419
|
+
chartId?: string;
|
|
420
|
+
pub?: number;
|
|
421
|
+
};
|
|
422
|
+
/** `POST importFile`: where the file was kept, and whether the agent was asked to import it. */
|
|
423
|
+
export interface ImportFileResponse {
|
|
424
|
+
path: string;
|
|
425
|
+
sentToAgent: boolean;
|
|
426
|
+
}
|
package/src/sheet-api.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract between a Sheets page and its server (the `sheet` capability).
|
|
3
|
+
*
|
|
4
|
+
* The workbook is an edit log: revision n is the workbook after the first n
|
|
5
|
+
* edits, each a list of engine operations written in a format version `v`
|
|
6
|
+
* and made on revision `base`. A page keeps its own engine session in step
|
|
7
|
+
* with the log: it reads a snapshot and loads the operations, hears every
|
|
8
|
+
* later edit on the `sheet` event of `_api/events`, and sends its own edits
|
|
9
|
+
* to `send`. Every new event connection gets a snapshot frame first, so a
|
|
10
|
+
* page that reconnects learns how far the log moved meanwhile.
|
|
11
|
+
*
|
|
12
|
+
* Every route is relative to the artifact's page base, as the runtime's
|
|
13
|
+
* `API` routes are.
|
|
14
|
+
*/
|
|
15
|
+
/** Route paths, relative to the page base. */
|
|
16
|
+
export const SHEET_API = {
|
|
17
|
+
/** `POST` {@link SheetReadRequest} → the read's answer. */
|
|
18
|
+
read: '_api/sheet/read',
|
|
19
|
+
/** `POST` {@link SheetSendRequest} → {@link SheetSendResponse}. */
|
|
20
|
+
send: '_api/sheet/send',
|
|
21
|
+
/** `POST` {@link WidgetRequest} → {@link WidgetResponse}. */
|
|
22
|
+
widget: '_api/sheet/widget',
|
|
23
|
+
/** `POST` a file's bytes (`?name=`), kept for the agent to import → {@link ImportFileResponse}. */
|
|
24
|
+
importFile: '_api/sheet/import',
|
|
25
|
+
};
|
|
26
|
+
/** The server-sent event name the frames arrive under on `_api/events`. */
|
|
27
|
+
export const SHEET_EVENT = 'sheet';
|
|
28
|
+
/**
|
|
29
|
+
* The server-sent event a walkthrough arrives under on `_api/events`. The agent sends one with the read
|
|
30
|
+
* `{"kind": "showGuide", "guide": {"stops": […]}}`; the server gives it to one page of the owner's, the one they used
|
|
31
|
+
* last, and to no one else.
|
|
32
|
+
*/
|
|
33
|
+
export const SHEET_WALKTHROUGH_EVENT = 'sheetWalkthrough';
|
|
34
|
+
export const MOST_VERSION_NAMES = 100;
|
|
35
|
+
export const MOST_VERSION_NAME_LENGTH = 100;
|
package/src/shell.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page side of the Open Artifacts Shell ("chrome") protocol.
|
|
3
|
+
*
|
|
4
|
+
* When a page runs inside the Shell (an iframe named `open-artifacts-shell` whose URL
|
|
5
|
+
* carries `open_artifacts_shell=<shell origin>`), the Shell draws the shared top bar
|
|
6
|
+
* (title, comments, share, export…). The page reports what it can do with
|
|
7
|
+
* `chrome_report` and answers the Shell's commands. Outside the Shell the
|
|
8
|
+
* page draws its own controls; {@link connectShell} then returns `null`.
|
|
9
|
+
*
|
|
10
|
+
* Messages only go to, and are only accepted from, the origin named by
|
|
11
|
+
* `open_artifacts_shell`.
|
|
12
|
+
*/
|
|
13
|
+
import { CHROME_PEER_KEY, MAX_CHROME_PEERS, type ChromeCommand, type ChromeDraw, type ChromeExportItem, type ChromeExportState, type ChromePeer, type ChromeReport } from '@openartifactsai/protocol';
|
|
14
|
+
export type { ChromeCommand, ChromeDraw, ChromeExportItem, ChromeExportState, ChromePeer, ChromeReport };
|
|
15
|
+
export { CHROME_PEER_KEY, MAX_CHROME_PEERS };
|
|
16
|
+
/** A connected Shell. */
|
|
17
|
+
export interface ShellConnection {
|
|
18
|
+
/** The Shell's origin. */
|
|
19
|
+
readonly origin: string;
|
|
20
|
+
/** The artifact's id from the Shell, `null` when it gave none (see {@link shellArtifactId}). */
|
|
21
|
+
readonly artifactId?: string | null;
|
|
22
|
+
/**
|
|
23
|
+
* What the Shell draws for the page (its last `chrome_hello`). While it
|
|
24
|
+
* has `saved`, the page leaves its own save badge out. Empty until the
|
|
25
|
+
* Shell says hello, and for Shells older than `draws`.
|
|
26
|
+
*/
|
|
27
|
+
readonly draws: ReadonlySet<ChromeDraw>;
|
|
28
|
+
/** Called after each `chrome_hello` (the Shell's `draws` may have changed). */
|
|
29
|
+
onHello(handler: (draws: ReadonlySet<ChromeDraw>) => void): () => void;
|
|
30
|
+
/** The Shell writes the clipboard for the page ({@link ShellConnection.writeClipboard}); false until it says hello. */
|
|
31
|
+
readonly writesClipboard: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Has the Shell write these formats to the clipboard, for a browser that
|
|
34
|
+
* keeps the clipboard from framed pages. Call it on the person's press,
|
|
35
|
+
* without awaiting anything first: the Shell can only write right after
|
|
36
|
+
* one. An image may still be drawing (a promise). Rejects with the Shell's
|
|
37
|
+
* reason, or when the Shell does not write the clipboard.
|
|
38
|
+
*/
|
|
39
|
+
writeClipboard(items: Record<string, Blob | PromiseLike<Blob>>): Promise<void>;
|
|
40
|
+
/** Answers an `export_format` command: `started`, then `done` or `declined` (or at once `busy`/`unsupported`). */
|
|
41
|
+
exportState(request: string, state: ChromeExportState, reason?: string): void;
|
|
42
|
+
/** Sends the full report; call again whenever any part changes. */
|
|
43
|
+
report(report: ChromeReport): void;
|
|
44
|
+
currentSheetPage(page: string | null): void;
|
|
45
|
+
copySheetLink(page: string): void;
|
|
46
|
+
currentDesignPage(page: string | null): void;
|
|
47
|
+
currentDocPlace(hash: string): void;
|
|
48
|
+
currentSlide(hash: string): void;
|
|
49
|
+
copySlideLink(hash: string): void;
|
|
50
|
+
/** Has the Shell copy the link to a whiteboard element (its address at `#element=<id>`). */
|
|
51
|
+
copyElementLink(id: string): void;
|
|
52
|
+
requestCommentMode(on: boolean, anchor?: string): void;
|
|
53
|
+
/** Handles commands; return the export items for `exports`. */
|
|
54
|
+
onCommand(handler: (command: ChromeCommand) => ChromeExportItem[] | void): () => void;
|
|
55
|
+
/**
|
|
56
|
+
* Handles `files_changed`. Return `true` when the page applied the change
|
|
57
|
+
* itself; otherwise the Shell reloads the frame after a second.
|
|
58
|
+
*/
|
|
59
|
+
onFilesChanged(handler: (paths: string[]) => boolean): () => void;
|
|
60
|
+
/** Stops listening. */
|
|
61
|
+
dispose(): void;
|
|
62
|
+
}
|
|
63
|
+
/** Protocol version spoken by this module. */
|
|
64
|
+
export declare const SHELL_PROTOCOL = 1;
|
|
65
|
+
/** Reads the Shell origin from the page URL, or `null` when not inside a Shell. */
|
|
66
|
+
export declare function shellOrigin(href?: string): string | null;
|
|
67
|
+
/**
|
|
68
|
+
* The artifact id the Shell put on the page URL (`open_artifacts_id`), or `null` when not inside a Shell or it gave none.
|
|
69
|
+
* Unlike the page's path, it stays the same across reloads on a cloud host, whose path carries a new token each time.
|
|
70
|
+
*/
|
|
71
|
+
export declare function shellArtifactId(href?: string): string | null;
|
|
72
|
+
/** Connects to the Shell, or returns `null` when the page is standalone. */
|
|
73
|
+
export declare function connectShell(): ShellConnection | null;
|