@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,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability contracts of the Open Artifacts page runtime.
|
|
3
|
+
*
|
|
4
|
+
* A type's page (an editor such as Design or Design System) never talks to its
|
|
5
|
+
* host directly. It asks `window.openartifacts.use(name)` for a capability
|
|
6
|
+
* namespace and calls the methods below. The host decides which capabilities a
|
|
7
|
+
* given viewer gets: `use()` resolves to `null` when a capability is not
|
|
8
|
+
* available for this view (read-only viewer, no host, unknown name).
|
|
9
|
+
*
|
|
10
|
+
* Every method is asynchronous and may reject with an {@link ArtifactError}.
|
|
11
|
+
*/
|
|
12
|
+
/** Version of the capability contract described in this file. */
|
|
13
|
+
export const CONTRACT_VERSION = '1.8.0';
|
|
14
|
+
/** The error object every capability rejects with. */
|
|
15
|
+
export class ArtifactError extends Error {
|
|
16
|
+
code;
|
|
17
|
+
/** Present for `conflict`: every path whose `ifMatch` failed. */
|
|
18
|
+
paths;
|
|
19
|
+
/** Present when asking again later may succeed (a busy or timed-out connector). */
|
|
20
|
+
retryable;
|
|
21
|
+
constructor(code, message, paths, retryable) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = 'ArtifactError';
|
|
24
|
+
this.code = code;
|
|
25
|
+
if (paths)
|
|
26
|
+
this.paths = paths;
|
|
27
|
+
if (retryable)
|
|
28
|
+
this.retryable = true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Type guard for {@link ArtifactError} that also works across realms (iframes). */
|
|
32
|
+
export function isArtifactError(value, code) {
|
|
33
|
+
if (!value || typeof value !== 'object')
|
|
34
|
+
return false;
|
|
35
|
+
const candidate = value;
|
|
36
|
+
if (candidate.name !== 'ArtifactError' || typeof candidate.code !== 'string')
|
|
37
|
+
return false;
|
|
38
|
+
return code === undefined || candidate.code === code;
|
|
39
|
+
}
|
|
40
|
+
/** A byte count a host may give as an upload limit (`maxBytes`): a positive whole number. */
|
|
41
|
+
export function validByteLimit(value) {
|
|
42
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
|
|
43
|
+
}
|
|
44
|
+
/** True when the role may change files and upload assets. */
|
|
45
|
+
export function canEdit(role) {
|
|
46
|
+
return role === 'owner' || role === 'editor';
|
|
47
|
+
}
|
|
48
|
+
/** Largest serialized {@link RoomMessage.data} a host relays. */
|
|
49
|
+
export const ROOM_MESSAGE_MAX_BYTES = 16_384;
|
|
50
|
+
/** Limits every host enforces on the document store. */
|
|
51
|
+
export const DB_LIMITS = {
|
|
52
|
+
/** Writes in one batch. */
|
|
53
|
+
maxWrites: 500,
|
|
54
|
+
/** Bytes of one document's JSON. */
|
|
55
|
+
maxDocumentBytes: 262_144,
|
|
56
|
+
/** Nesting depth of one document. */
|
|
57
|
+
maxDepth: 32,
|
|
58
|
+
};
|
|
59
|
+
/** Every {@link McpErrorCode}. */
|
|
60
|
+
export const MCP_ERROR_CODES = [
|
|
61
|
+
'server_not_connected',
|
|
62
|
+
'needs_reauth',
|
|
63
|
+
'not_granted',
|
|
64
|
+
'not_declared',
|
|
65
|
+
'not_in_manifest',
|
|
66
|
+
'consent_required',
|
|
67
|
+
'selection_required',
|
|
68
|
+
'rate_limited',
|
|
69
|
+
'upstream_error',
|
|
70
|
+
'tool_error',
|
|
71
|
+
'capability_disabled',
|
|
72
|
+
'capability_removed',
|
|
73
|
+
'server_unavailable',
|
|
74
|
+
'response_too_large',
|
|
75
|
+
];
|
|
76
|
+
/** Default and largest {@link McpCallOptions.timeoutMs}. */
|
|
77
|
+
export const MCP_CALL_TIMEOUT = { defaultMs: 120_000, maxMs: 600_000 };
|
package/src/client.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Installs `window.openartifacts` on top of a capability provider.
|
|
3
|
+
*
|
|
4
|
+
* The provider is whatever actually implements the capabilities: the local
|
|
5
|
+
* type server ({@link createLocalProvider}), a test double, or a bridge to a
|
|
6
|
+
* remote host. This module adds the guarantees every page relies on:
|
|
7
|
+
* memoized and frozen namespaces, and a timeout so a missing host resolves to
|
|
8
|
+
* `null` instead of hanging forever.
|
|
9
|
+
*/
|
|
10
|
+
import { type CapabilityMap, type CapabilityName, type OpenArtifactsRuntime } from './capabilities.js';
|
|
11
|
+
export { LEGACY_SHELL_PARAMS, adoptLegacyBrowserStorage, adoptLegacyStorage, type StorageList } from '@openartifactsai/protocol/legacy-wire';
|
|
12
|
+
/** The global's name before the rename: editors built on an older runtime look for `window.openartifact`. */
|
|
13
|
+
export declare const LEGACY_RUNTIME_GLOBAL = "openartifact";
|
|
14
|
+
/** Something that can produce capability namespaces. */
|
|
15
|
+
export interface CapabilityProvider {
|
|
16
|
+
/** Returns the namespace, or `null` when this view may not use it. */
|
|
17
|
+
get<K extends CapabilityName>(name: K): Promise<CapabilityMap[K] | null> | CapabilityMap[K] | null;
|
|
18
|
+
}
|
|
19
|
+
/** Options of {@link createRuntime}. */
|
|
20
|
+
export interface RuntimeOptions {
|
|
21
|
+
/** Milliseconds before an unanswered `use()` resolves to `null`. Default 10 000. */
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
}
|
|
24
|
+
/** Builds a runtime object without installing it globally. */
|
|
25
|
+
export declare function createRuntime(provider: CapabilityProvider, options?: RuntimeOptions): OpenArtifactsRuntime;
|
|
26
|
+
/**
|
|
27
|
+
* Installs the runtime at `window.openartifacts` (once, with `window.openartifact` as the same object for editors built
|
|
28
|
+
* before the rename) and returns it. A runtime already installed by the host wins: pages call this defensively. It
|
|
29
|
+
* first moves what an older version kept in this page's storage to the new keys.
|
|
30
|
+
*/
|
|
31
|
+
export declare function installRuntime(provider: CapabilityProvider, options?: RuntimeOptions): OpenArtifactsRuntime;
|
|
32
|
+
/** Shortcut for `window.openartifacts?.use(name)` that never throws. */
|
|
33
|
+
export declare function useCapability<K extends CapabilityName>(name: K): Promise<CapabilityMap[K] | null>;
|
package/src/client.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Installs `window.openartifacts` on top of a capability provider.
|
|
3
|
+
*
|
|
4
|
+
* The provider is whatever actually implements the capabilities: the local
|
|
5
|
+
* type server ({@link createLocalProvider}), a test double, or a bridge to a
|
|
6
|
+
* remote host. This module adds the guarantees every page relies on:
|
|
7
|
+
* memoized and frozen namespaces, and a timeout so a missing host resolves to
|
|
8
|
+
* `null` instead of hanging forever.
|
|
9
|
+
*/
|
|
10
|
+
import { adoptLegacyBrowserStorage } from '@openartifactsai/protocol/legacy-wire';
|
|
11
|
+
import { CONTRACT_VERSION, } from "./capabilities.js";
|
|
12
|
+
export { LEGACY_SHELL_PARAMS, adoptLegacyBrowserStorage, adoptLegacyStorage } from '@openartifactsai/protocol/legacy-wire';
|
|
13
|
+
/** The global's name before the rename: editors built on an older runtime look for `window.openartifact`. */
|
|
14
|
+
export const LEGACY_RUNTIME_GLOBAL = 'openartifact';
|
|
15
|
+
const LEGACY_GLOBAL = LEGACY_RUNTIME_GLOBAL;
|
|
16
|
+
/** The runtime installed on this page, under its name or the one from before the rename. */
|
|
17
|
+
const installed = () => globalThis.window?.openartifacts ?? globalThis.window?.[LEGACY_GLOBAL];
|
|
18
|
+
/** Builds a runtime object without installing it globally. */
|
|
19
|
+
export function createRuntime(provider, options = {}) {
|
|
20
|
+
const timeoutMs = options.timeoutMs ?? 10_000;
|
|
21
|
+
const cache = new Map();
|
|
22
|
+
const use = (name) => {
|
|
23
|
+
const cached = cache.get(name);
|
|
24
|
+
if (cached)
|
|
25
|
+
return cached;
|
|
26
|
+
const pending = new Promise((resolve) => {
|
|
27
|
+
const timer = setTimeout(() => resolve(null), timeoutMs);
|
|
28
|
+
Promise.resolve()
|
|
29
|
+
.then(() => provider.get(name))
|
|
30
|
+
.then((namespace) => {
|
|
31
|
+
clearTimeout(timer);
|
|
32
|
+
resolve(namespace ? Object.freeze(namespace) : null);
|
|
33
|
+
}, () => {
|
|
34
|
+
clearTimeout(timer);
|
|
35
|
+
resolve(null);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
cache.set(name, pending);
|
|
39
|
+
return pending;
|
|
40
|
+
};
|
|
41
|
+
return Object.freeze({ version: CONTRACT_VERSION, use });
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Installs the runtime at `window.openartifacts` (once, with `window.openartifact` as the same object for editors built
|
|
45
|
+
* before the rename) and returns it. A runtime already installed by the host wins: pages call this defensively. It
|
|
46
|
+
* first moves what an older version kept in this page's storage to the new keys.
|
|
47
|
+
*/
|
|
48
|
+
export function installRuntime(provider, options) {
|
|
49
|
+
adoptLegacyBrowserStorage();
|
|
50
|
+
const existing = installed();
|
|
51
|
+
if (existing)
|
|
52
|
+
return existing;
|
|
53
|
+
const runtime = createRuntime(provider, options);
|
|
54
|
+
Object.defineProperty(window, 'openartifacts', {
|
|
55
|
+
value: runtime,
|
|
56
|
+
configurable: false,
|
|
57
|
+
enumerable: true,
|
|
58
|
+
writable: false,
|
|
59
|
+
});
|
|
60
|
+
if (!Object.prototype.hasOwnProperty.call(window, LEGACY_GLOBAL)) {
|
|
61
|
+
Object.defineProperty(window, LEGACY_GLOBAL, { value: runtime, configurable: false, enumerable: false, writable: false });
|
|
62
|
+
}
|
|
63
|
+
return runtime;
|
|
64
|
+
}
|
|
65
|
+
/** Shortcut for `window.openartifacts?.use(name)` that never throws. */
|
|
66
|
+
export async function useCapability(name) {
|
|
67
|
+
const runtime = installed();
|
|
68
|
+
if (!runtime)
|
|
69
|
+
return null;
|
|
70
|
+
try {
|
|
71
|
+
return await runtime.use(name);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
package/src/doc-api.d.ts
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract between a Docs page and its server (the `doc` capability).
|
|
3
|
+
*
|
|
4
|
+
* A doc is a list of tabs; each tab's body is a tree of blocks whose blocks
|
|
5
|
+
* and characters carry stable ids (`<session>.<n>`), and a revision number
|
|
6
|
+
* (`rev`) the server raises on every write. A page takes a writing session
|
|
7
|
+
* (`session`), reads a tab (`read`), and sends its edits as ops on the
|
|
8
|
+
* revision it holds (`call`, an `update` of the tab's body node). Every
|
|
9
|
+
* write anyone makes is announced on the `doc` event of `_api/events`; a
|
|
10
|
+
* page that did not make it reads the tab again.
|
|
11
|
+
*
|
|
12
|
+
* Every route is relative to the artifact's page base, as the runtime's
|
|
13
|
+
* `API` routes are.
|
|
14
|
+
*/
|
|
15
|
+
export type DocJson = null | boolean | number | string | DocJson[] | {
|
|
16
|
+
[key: string]: DocJson;
|
|
17
|
+
};
|
|
18
|
+
export type DocJsonObject = {
|
|
19
|
+
[key: string]: DocJson;
|
|
20
|
+
};
|
|
21
|
+
/** Route paths, relative to the page base. */
|
|
22
|
+
export declare const DOC_API: {
|
|
23
|
+
/** `POST` {@link DocSessionRequest} → {@link DocSessionResponse}. */
|
|
24
|
+
readonly session: "_api/doc/session";
|
|
25
|
+
/** `POST` {@link DocReadRequest} → {@link DocTabResponse}. */
|
|
26
|
+
readonly read: "_api/doc/read";
|
|
27
|
+
/** `POST` {@link DocCallRequest} → {@link DocCallAnswer}. */
|
|
28
|
+
readonly call: "_api/doc/call";
|
|
29
|
+
/** `POST` {@link DocHistoryRequest} → {@link DocHistoryResponse}. */
|
|
30
|
+
readonly history: "_api/doc/history";
|
|
31
|
+
/** `POST` {@link DocVersionRequest} → {@link DocVersionResponse}. */
|
|
32
|
+
readonly version: "_api/doc/version";
|
|
33
|
+
/** `POST` {@link DocRestoreRequest} → {@link DocRestoreResponse}. */
|
|
34
|
+
readonly restore: "_api/doc/restore";
|
|
35
|
+
/** `POST` a file's bytes (`?name=`, optional `&tabName=`) → {@link DocImportResponse}. */
|
|
36
|
+
readonly importFile: "_api/doc/import";
|
|
37
|
+
/** `GET ?format=&tab=&paper=` → the file's bytes. */
|
|
38
|
+
readonly exportFile: "_api/doc/export";
|
|
39
|
+
};
|
|
40
|
+
/** The server-sent event name the frames arrive under on `_api/events`. */
|
|
41
|
+
export declare const DOC_EVENT = "doc";
|
|
42
|
+
/** The doc's export formats. */
|
|
43
|
+
export type DocExportFormat = 'markdown' | 'docx' | 'pdf' | 'html';
|
|
44
|
+
/** Paper sizes of a printed export. */
|
|
45
|
+
export type DocPaper = 'a4' | 'letter';
|
|
46
|
+
/** What the page asks of a dropdown list's option. */
|
|
47
|
+
export interface DocEnumOption {
|
|
48
|
+
name: string;
|
|
49
|
+
order: number;
|
|
50
|
+
disabled: boolean;
|
|
51
|
+
color?: string;
|
|
52
|
+
}
|
|
53
|
+
/** A dropdown list (a dropdown chip names its option by position). */
|
|
54
|
+
export interface DocEnum {
|
|
55
|
+
id: string;
|
|
56
|
+
name: string;
|
|
57
|
+
options: DocEnumOption[];
|
|
58
|
+
}
|
|
59
|
+
/** A tab, as the doc lists it. */
|
|
60
|
+
export interface DocFile {
|
|
61
|
+
id: string;
|
|
62
|
+
name: string;
|
|
63
|
+
/** Sort key: tabs are shown in the string order of these. */
|
|
64
|
+
order: string;
|
|
65
|
+
/** The tab this one sits under in the tab list. */
|
|
66
|
+
subtabOf?: string;
|
|
67
|
+
rev: number;
|
|
68
|
+
/** The tab's body node: the page writes the tab through it. */
|
|
69
|
+
content: {
|
|
70
|
+
kind: 'node';
|
|
71
|
+
id: string;
|
|
72
|
+
engine: 'prose';
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** The doc: its name, tabs, dropdown lists and display record. */
|
|
76
|
+
export interface DocProject {
|
|
77
|
+
id: string;
|
|
78
|
+
name: string;
|
|
79
|
+
/** Raised on every write anywhere in the doc. */
|
|
80
|
+
head: number;
|
|
81
|
+
updated: string;
|
|
82
|
+
files: DocFile[];
|
|
83
|
+
enums: DocEnum[];
|
|
84
|
+
/** How the page shows the doc (fonts, page width, where the tabs go). The page owns the keys. */
|
|
85
|
+
display?: DocJsonObject;
|
|
86
|
+
/** Set while an owner has locked the doc: nobody can edit it until an owner unlocks it. */
|
|
87
|
+
locked?: DocLockInfo;
|
|
88
|
+
}
|
|
89
|
+
/** Who locked a doc, when, and why. */
|
|
90
|
+
export interface DocLockInfo {
|
|
91
|
+
by: {
|
|
92
|
+
id: string;
|
|
93
|
+
name: string;
|
|
94
|
+
};
|
|
95
|
+
at: string;
|
|
96
|
+
note?: string;
|
|
97
|
+
}
|
|
98
|
+
/** `POST session`: a writing session for this page connection (`client` is the event stream's id). */
|
|
99
|
+
export interface DocSessionRequest {
|
|
100
|
+
client: string;
|
|
101
|
+
}
|
|
102
|
+
export interface DocSessionResponse {
|
|
103
|
+
/** The writing session: new ids the page makes are `<sess>.<n>` from `next` on. `null` for a reader. */
|
|
104
|
+
sess: string | null;
|
|
105
|
+
next: number;
|
|
106
|
+
writable: boolean;
|
|
107
|
+
commentable: boolean;
|
|
108
|
+
/** The person, as suggestions name them (`by`). */
|
|
109
|
+
me: {
|
|
110
|
+
id: string;
|
|
111
|
+
name: string;
|
|
112
|
+
};
|
|
113
|
+
project: DocProject;
|
|
114
|
+
/** The names of the people who worked on the doc, by the id versions and suggestions name them with. */
|
|
115
|
+
people?: Record<string, string>;
|
|
116
|
+
}
|
|
117
|
+
/** `POST read`: a tab as the server holds it. */
|
|
118
|
+
export interface DocReadRequest {
|
|
119
|
+
tab: string;
|
|
120
|
+
}
|
|
121
|
+
/** Who made an open suggestion. */
|
|
122
|
+
export interface DocSuggestion {
|
|
123
|
+
id: string;
|
|
124
|
+
by: string;
|
|
125
|
+
/** The name `by` goes by, when the doc knows it (not for the agent's). */
|
|
126
|
+
name?: string;
|
|
127
|
+
at: string;
|
|
128
|
+
/** `agent`: the agent laid it. */
|
|
129
|
+
via?: string;
|
|
130
|
+
mine: boolean;
|
|
131
|
+
/** A hash of what the suggestion holds now: a decision is made on it. */
|
|
132
|
+
asOf: string;
|
|
133
|
+
}
|
|
134
|
+
export interface DocTabResponse {
|
|
135
|
+
tab: string;
|
|
136
|
+
rev: number;
|
|
137
|
+
/** The tab's content as stored (`{rev, blocks, suggestions?}`, text kept as runs). */
|
|
138
|
+
doc: DocJsonObject;
|
|
139
|
+
suggestions: DocSuggestion[];
|
|
140
|
+
}
|
|
141
|
+
/** One member of a call: a verb on an object (`project`, `file`, `node`, `enum`). */
|
|
142
|
+
export interface DocMember {
|
|
143
|
+
verb: 'read' | 'create' | 'update' | 'delete';
|
|
144
|
+
object?: 'project' | 'file' | 'node' | 'enum';
|
|
145
|
+
ref?: {
|
|
146
|
+
object: 'project' | 'file' | 'node' | 'enum';
|
|
147
|
+
id: string;
|
|
148
|
+
};
|
|
149
|
+
payload?: DocJsonObject;
|
|
150
|
+
engine?: string;
|
|
151
|
+
/** An alias later members name as `$lid:<alias>` for what this one makes. */
|
|
152
|
+
$lid?: string;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* `POST call`: one member, or a batch that lands whole. `opId` makes a call
|
|
156
|
+
* safe to send again (after a reconnect): an allowed call is answered again,
|
|
157
|
+
* not run twice.
|
|
158
|
+
*/
|
|
159
|
+
export type DocCallRequest = {
|
|
160
|
+
sess: string;
|
|
161
|
+
opId?: string;
|
|
162
|
+
member: DocMember;
|
|
163
|
+
} | {
|
|
164
|
+
sess: string;
|
|
165
|
+
opId?: string;
|
|
166
|
+
batch: DocMember[];
|
|
167
|
+
};
|
|
168
|
+
export type DocCallAnswer = ({
|
|
169
|
+
verdict: 'allow';
|
|
170
|
+
replayed?: true;
|
|
171
|
+
} & DocJsonObject) | {
|
|
172
|
+
verdict: 'deny';
|
|
173
|
+
/** A refusal code (`guard_mismatch`, `block_gone`, `not_your_session`, …). */
|
|
174
|
+
reason: string;
|
|
175
|
+
detail: string;
|
|
176
|
+
/** The batch member, or the op of an update, that was refused. */
|
|
177
|
+
index?: number;
|
|
178
|
+
data?: DocJsonObject;
|
|
179
|
+
};
|
|
180
|
+
/** A write somebody made to a tab. */
|
|
181
|
+
export interface DocTabFrame {
|
|
182
|
+
kind: 'tab';
|
|
183
|
+
tab: string;
|
|
184
|
+
rev: number;
|
|
185
|
+
by: 'person' | 'agent';
|
|
186
|
+
/** The session that wrote it, and the page's own id for the call. */
|
|
187
|
+
sess?: string;
|
|
188
|
+
opId?: string;
|
|
189
|
+
/** The blocks the write changed, added or removed (the agent's writes). */
|
|
190
|
+
blocks?: string[];
|
|
191
|
+
}
|
|
192
|
+
/** The doc's name, tabs or display record changed. */
|
|
193
|
+
export interface DocProjectFrame {
|
|
194
|
+
kind: 'project';
|
|
195
|
+
project: DocProject;
|
|
196
|
+
}
|
|
197
|
+
/** Dropdown lists made or changed. */
|
|
198
|
+
export interface DocEnumsFrame {
|
|
199
|
+
kind: 'enums';
|
|
200
|
+
enums: DocEnum[];
|
|
201
|
+
}
|
|
202
|
+
/** The page's event stream opened: sent first on every connection, so a page that was cut off reads what it missed. */
|
|
203
|
+
export interface DocStreamFrame {
|
|
204
|
+
kind: 'stream';
|
|
205
|
+
}
|
|
206
|
+
export type DocFrame = DocTabFrame | DocProjectFrame | DocEnumsFrame | DocStreamFrame;
|
|
207
|
+
/** `POST history`: a tab's kept versions. */
|
|
208
|
+
export interface DocHistoryRequest {
|
|
209
|
+
tab: string;
|
|
210
|
+
}
|
|
211
|
+
/** A kept version of a tab. */
|
|
212
|
+
export interface DocVersion {
|
|
213
|
+
rev: number;
|
|
214
|
+
/** `human`: a person on the page; `agent`: the agent; `system`: from before the history began. */
|
|
215
|
+
by: 'human' | 'agent' | 'system';
|
|
216
|
+
/** The person's id. */
|
|
217
|
+
user?: string;
|
|
218
|
+
/** The name that person goes by, when the doc knows it. */
|
|
219
|
+
name?: string;
|
|
220
|
+
at: string;
|
|
221
|
+
/** A restore: the rev it brought back. */
|
|
222
|
+
restoredFrom?: number;
|
|
223
|
+
}
|
|
224
|
+
export interface DocHistoryResponse {
|
|
225
|
+
tab: string;
|
|
226
|
+
rev: number;
|
|
227
|
+
/** Newest first. */
|
|
228
|
+
versions: DocVersion[];
|
|
229
|
+
}
|
|
230
|
+
/** `POST version`: a tab as it stood at a kept rev. */
|
|
231
|
+
export interface DocVersionRequest {
|
|
232
|
+
tab: string;
|
|
233
|
+
rev: number;
|
|
234
|
+
}
|
|
235
|
+
export interface DocVersionResponse {
|
|
236
|
+
tab: string;
|
|
237
|
+
rev: number;
|
|
238
|
+
/** As {@link DocTabResponse.doc}, with the suggestions open in that version. */
|
|
239
|
+
doc: DocJsonObject;
|
|
240
|
+
}
|
|
241
|
+
/** `POST restore`: the tab back as it was at `rev`, as a new write; `ifRev` is the rev the page last saw. */
|
|
242
|
+
export interface DocRestoreRequest {
|
|
243
|
+
tab: string;
|
|
244
|
+
rev: number;
|
|
245
|
+
ifRev?: number;
|
|
246
|
+
}
|
|
247
|
+
export interface DocRestoreResponse {
|
|
248
|
+
restored: boolean;
|
|
249
|
+
/** The tab's rev now, and before the restore. */
|
|
250
|
+
rev: number;
|
|
251
|
+
before: number;
|
|
252
|
+
}
|
|
253
|
+
/** The kinds of file an import reads. */
|
|
254
|
+
export type DocImportFormat = 'markdown' | 'docx' | 'pdf';
|
|
255
|
+
/** What didn't come across whole, counted: `what` says it in a few words, shown as it is. */
|
|
256
|
+
export interface DocImportNote {
|
|
257
|
+
what: string;
|
|
258
|
+
count: number;
|
|
259
|
+
}
|
|
260
|
+
/** What an import added. */
|
|
261
|
+
export interface DocImportResponse {
|
|
262
|
+
ok: true;
|
|
263
|
+
format: DocImportFormat;
|
|
264
|
+
/** The new tabs, in order. */
|
|
265
|
+
tabs: {
|
|
266
|
+
id: string;
|
|
267
|
+
name: string;
|
|
268
|
+
}[];
|
|
269
|
+
/** The file's size. */
|
|
270
|
+
bytes: number;
|
|
271
|
+
/** How many pictures it brought. */
|
|
272
|
+
images: number;
|
|
273
|
+
notes: DocImportNote[];
|
|
274
|
+
/** A doc made from the file, when the folder held none. */
|
|
275
|
+
created?: {
|
|
276
|
+
id: string;
|
|
277
|
+
name: string;
|
|
278
|
+
root: string;
|
|
279
|
+
};
|
|
280
|
+
}
|
package/src/doc-api.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract between a Docs page and its server (the `doc` capability).
|
|
3
|
+
*
|
|
4
|
+
* A doc is a list of tabs; each tab's body is a tree of blocks whose blocks
|
|
5
|
+
* and characters carry stable ids (`<session>.<n>`), and a revision number
|
|
6
|
+
* (`rev`) the server raises on every write. A page takes a writing session
|
|
7
|
+
* (`session`), reads a tab (`read`), and sends its edits as ops on the
|
|
8
|
+
* revision it holds (`call`, an `update` of the tab's body node). Every
|
|
9
|
+
* write anyone makes is announced on the `doc` event of `_api/events`; a
|
|
10
|
+
* page that did not make it reads the tab again.
|
|
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 DOC_API = {
|
|
17
|
+
/** `POST` {@link DocSessionRequest} → {@link DocSessionResponse}. */
|
|
18
|
+
session: '_api/doc/session',
|
|
19
|
+
/** `POST` {@link DocReadRequest} → {@link DocTabResponse}. */
|
|
20
|
+
read: '_api/doc/read',
|
|
21
|
+
/** `POST` {@link DocCallRequest} → {@link DocCallAnswer}. */
|
|
22
|
+
call: '_api/doc/call',
|
|
23
|
+
/** `POST` {@link DocHistoryRequest} → {@link DocHistoryResponse}. */
|
|
24
|
+
history: '_api/doc/history',
|
|
25
|
+
/** `POST` {@link DocVersionRequest} → {@link DocVersionResponse}. */
|
|
26
|
+
version: '_api/doc/version',
|
|
27
|
+
/** `POST` {@link DocRestoreRequest} → {@link DocRestoreResponse}. */
|
|
28
|
+
restore: '_api/doc/restore',
|
|
29
|
+
/** `POST` a file's bytes (`?name=`, optional `&tabName=`) → {@link DocImportResponse}. */
|
|
30
|
+
importFile: '_api/doc/import',
|
|
31
|
+
/** `GET ?format=&tab=&paper=` → the file's bytes. */
|
|
32
|
+
exportFile: '_api/doc/export',
|
|
33
|
+
};
|
|
34
|
+
/** The server-sent event name the frames arrive under on `_api/events`. */
|
|
35
|
+
export const DOC_EVENT = 'doc';
|