@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,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HTTP contract between an editor page and its local type server.
|
|
3
|
+
*
|
|
4
|
+
* Every route is relative to the artifact's page base (for example
|
|
5
|
+
* `http://127.0.0.1:4720/design/<token>/`). Both the browser provider
|
|
6
|
+
* ({@link ./local-provider.ts}) and the Node server (`@openartifactsai/type-server`)
|
|
7
|
+
* import these names and shapes, so the two sides cannot drift apart.
|
|
8
|
+
*/
|
|
9
|
+
import type { AgentDelivery, AgentRequest, AgentSendResult, AgentStatus, ArtifactErrorCode, CommentCreate, CommentThread, ConflictPath, DbChangeEvent, DbDocument, DbOrder, DbReceipt, DbWrite, FileListing, FilesChangedEvent, HistoryChangeEvent, HistoryFileDiff, HistoryListing, HistoryRestoreResult, JsonRecord, JsonValue, McpServerEntry, McpToolResult, Participant, Peer, PublishBatch, PublishResult, RoomMessage, SelectionSnapshot, Viewer } from './capabilities.js';
|
|
10
|
+
import type { SheetFrame, SheetWalkthrough } from './sheet-api.js';
|
|
11
|
+
import type { DocFrame } from './doc-api.js';
|
|
12
|
+
/** Route paths, relative to the page base. */
|
|
13
|
+
export declare const API: {
|
|
14
|
+
readonly session: "_api/session";
|
|
15
|
+
readonly files: "_api/files";
|
|
16
|
+
readonly file: "_api/file";
|
|
17
|
+
readonly publish: "_api/publish";
|
|
18
|
+
readonly assets: "_api/assets";
|
|
19
|
+
readonly events: "_api/events";
|
|
20
|
+
readonly agentSend: "_api/agent/send";
|
|
21
|
+
readonly presence: "_api/presence";
|
|
22
|
+
readonly peers: "_api/peers";
|
|
23
|
+
readonly participants: "_api/participants";
|
|
24
|
+
readonly downloads: "_api/downloads";
|
|
25
|
+
readonly roomEmit: "_api/room/emit";
|
|
26
|
+
readonly dbGet: "_api/db/get";
|
|
27
|
+
readonly dbList: "_api/db/list";
|
|
28
|
+
readonly dbWrite: "_api/db/write";
|
|
29
|
+
readonly comments: "_api/comments";
|
|
30
|
+
readonly commentsCreate: "_api/comments/create";
|
|
31
|
+
readonly commentsReply: "_api/comments/reply";
|
|
32
|
+
readonly commentsEdit: "_api/comments/edit";
|
|
33
|
+
readonly commentsReact: "_api/comments/react";
|
|
34
|
+
readonly commentsResolve: "_api/comments/resolve";
|
|
35
|
+
readonly commentsMove: "_api/comments/move";
|
|
36
|
+
readonly commentsRemove: "_api/comments/remove";
|
|
37
|
+
readonly commentsSend: "_api/comments/send";
|
|
38
|
+
readonly history: "_api/history";
|
|
39
|
+
readonly historyFiles: "_api/history/files";
|
|
40
|
+
readonly historyFile: "_api/history/file";
|
|
41
|
+
readonly historyDiff: "_api/history/diff";
|
|
42
|
+
readonly historyRestore: "_api/history/restore";
|
|
43
|
+
readonly historyDismiss: "_api/history/dismiss";
|
|
44
|
+
readonly historyNote: "_api/history/note";
|
|
45
|
+
readonly systemCopy: "_api/design/system-copy";
|
|
46
|
+
readonly mcpTools: "_api/mcp/tools";
|
|
47
|
+
readonly mcpCall: "_api/mcp/call";
|
|
48
|
+
/**
|
|
49
|
+
* `POST` {@link DataRefreshRequest} → {@link DataRefreshResponse}: a hosted Data dashboard asks its owner's computer to
|
|
50
|
+
* run its live queries again (the host queues it; no connector runs there).
|
|
51
|
+
*/
|
|
52
|
+
readonly dataRefresh: "_api/data/refresh";
|
|
53
|
+
/** `GET` → {@link DataSharesResponse}: the connectors whose access the owner shares on this dashboard. */
|
|
54
|
+
readonly dataShares: "_api/data/shares";
|
|
55
|
+
/** `POST` {@link DataShareRequest} → {@link DataShareResponse}: the owner shares (or, with no calls, stops sharing) a connector. */
|
|
56
|
+
readonly dataShare: "_api/data/share";
|
|
57
|
+
/** `POST` {@link DataSharedRequest} → {@link DataSharedResponse}: runs approved calls with the sharer's connector. */
|
|
58
|
+
readonly dataShared: "_api/data/shared";
|
|
59
|
+
/**
|
|
60
|
+
* `POST` {@link FrameSampleRequest} (`client`: the page's id): one `sample` call of the editor, answered as an NDJSON
|
|
61
|
+
* stream of `SampleStreamEvent`s until `done` or `error` (a refusal is one `error` line). Closing the request cancels
|
|
62
|
+
* the call. The owner only, on this computer.
|
|
63
|
+
*/
|
|
64
|
+
readonly sample: "_api/sample";
|
|
65
|
+
/** `POST` {@link FrameSampleToolRequest}: one round's tool results; answers `{ok: true}` or `{error}`. */
|
|
66
|
+
readonly sampleTool: "_api/sample/tool";
|
|
67
|
+
/** `GET ?client=` → `SampleLimits`, or `{error}`. */
|
|
68
|
+
readonly sampleLimits: "_api/sample/limits";
|
|
69
|
+
/** `GET` → {@link SampleStateResponse}: whether a call would go ahead without a consent dialog. */
|
|
70
|
+
readonly sampleState: "_api/sample/state";
|
|
71
|
+
};
|
|
72
|
+
/** `GET _api/sample/state` 200 body: `granted` (the person's grants cover the artifact), `denied`, or `none` (it would ask). */
|
|
73
|
+
export interface SampleStateResponse {
|
|
74
|
+
state: 'granted' | 'denied' | 'none';
|
|
75
|
+
}
|
|
76
|
+
/** One exact call a share approves: its arguments keep their `{{filter}}` blanks. */
|
|
77
|
+
export interface SharedConnectorCall {
|
|
78
|
+
connector: string;
|
|
79
|
+
tool: string;
|
|
80
|
+
/** The source is written `kind: "call"` (filters with rules). */
|
|
81
|
+
call?: true;
|
|
82
|
+
args: Record<string, unknown>;
|
|
83
|
+
rules?: Record<string, unknown>;
|
|
84
|
+
}
|
|
85
|
+
/** Who shares a connector, and since when (ms since the epoch). */
|
|
86
|
+
export interface ConnectorShareHolder {
|
|
87
|
+
sharer: {
|
|
88
|
+
id: string;
|
|
89
|
+
name: string;
|
|
90
|
+
};
|
|
91
|
+
at: number;
|
|
92
|
+
}
|
|
93
|
+
/** `GET _api/data/shares`: each shared connector, with the key of every call it approves. */
|
|
94
|
+
export interface DataSharesResponse {
|
|
95
|
+
shares: (ConnectorShareHolder & {
|
|
96
|
+
connector: string;
|
|
97
|
+
keys: string[];
|
|
98
|
+
})[];
|
|
99
|
+
}
|
|
100
|
+
/** `POST _api/data/share`: the calls to approve; none stops sharing. */
|
|
101
|
+
export interface DataShareRequest {
|
|
102
|
+
connector: string;
|
|
103
|
+
calls: SharedConnectorCall[];
|
|
104
|
+
}
|
|
105
|
+
export interface DataShareResponse {
|
|
106
|
+
connector: string;
|
|
107
|
+
/** `null` once sharing stopped. */
|
|
108
|
+
holder: ConnectorShareHolder | null;
|
|
109
|
+
count: number;
|
|
110
|
+
}
|
|
111
|
+
/** One call a viewer asks to run as the sharer, with the filter values it fills its blanks with. */
|
|
112
|
+
export interface SharedCallRequest extends SharedConnectorCall {
|
|
113
|
+
params?: Record<string, unknown>;
|
|
114
|
+
}
|
|
115
|
+
/** `POST _api/data/shared`. `reuseMs` is how long the page reuses results (never under five minutes here). */
|
|
116
|
+
export interface DataSharedRequest {
|
|
117
|
+
calls: SharedCallRequest[];
|
|
118
|
+
reuseMs?: number;
|
|
119
|
+
refresh?: boolean;
|
|
120
|
+
}
|
|
121
|
+
/** Why a shared call gave no result. */
|
|
122
|
+
export type SharedCallCode = 'not_shared' | 'invalid_call' | 'not_approved' | 'value_refused' | 'tool_error' | 'too_large' | 'timeout' | 'connector_unavailable';
|
|
123
|
+
export type SharedCallAnswer = (ConnectorShareHolder & {
|
|
124
|
+
ok: true;
|
|
125
|
+
result: Record<string, unknown>;
|
|
126
|
+
ranAt: number;
|
|
127
|
+
}) | {
|
|
128
|
+
ok: false;
|
|
129
|
+
code: SharedCallCode;
|
|
130
|
+
message?: string;
|
|
131
|
+
sharer?: {
|
|
132
|
+
id: string;
|
|
133
|
+
name: string;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
export interface DataSharedResponse {
|
|
137
|
+
answers: SharedCallAnswer[];
|
|
138
|
+
}
|
|
139
|
+
/** `POST _api/data/refresh`: the dataset ids to refresh, all live queries when left out. */
|
|
140
|
+
export interface DataRefreshRequest {
|
|
141
|
+
queries?: string[];
|
|
142
|
+
}
|
|
143
|
+
/** `POST _api/data/refresh`'s answer: queued; `online` says whether the owner's computer is linked now to take it. */
|
|
144
|
+
export interface DataRefreshResponse {
|
|
145
|
+
queued: true;
|
|
146
|
+
online: boolean;
|
|
147
|
+
}
|
|
148
|
+
/** Root-relative prefix every upload is served under. */
|
|
149
|
+
export declare const BLOB_PREFIX = "/_blob/";
|
|
150
|
+
/** `GET _api/session` */
|
|
151
|
+
export interface SessionResponse {
|
|
152
|
+
artifact: {
|
|
153
|
+
id: string;
|
|
154
|
+
title: string;
|
|
155
|
+
type: string;
|
|
156
|
+
};
|
|
157
|
+
viewer: Viewer;
|
|
158
|
+
agent: AgentStatus;
|
|
159
|
+
/** The largest upload (`POST _api/assets`) this server takes for the artifact, in bytes. Left out: 20 MB. */
|
|
160
|
+
uploadMaxBytes?: number;
|
|
161
|
+
/** Stores the type keeps beside its files; absent ones are not offered (`db` / `comments` resolve `null`). */
|
|
162
|
+
stores?: {
|
|
163
|
+
systemCopy?: boolean;
|
|
164
|
+
db?: boolean;
|
|
165
|
+
comments?: boolean;
|
|
166
|
+
history?: boolean;
|
|
167
|
+
sheet?: boolean;
|
|
168
|
+
doc?: boolean;
|
|
169
|
+
/** The `sample` routes are served for this viewer (the owner, a daemon that streams `sample`, not hosted). */
|
|
170
|
+
sample?: boolean;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/** `GET _api/files` */
|
|
174
|
+
export interface FilesResponse {
|
|
175
|
+
files: FileListing;
|
|
176
|
+
}
|
|
177
|
+
/** Header carrying the SHA-256 of a file returned by `GET _api/file`. */
|
|
178
|
+
export declare const SHA_HEADER = "x-open-artifacts-sha256";
|
|
179
|
+
/** `POST _api/publish` request body. */
|
|
180
|
+
export interface PublishRequest {
|
|
181
|
+
files: PublishBatch;
|
|
182
|
+
/** The publishing page's client id, so its own change events are not echoed back. */
|
|
183
|
+
client: string;
|
|
184
|
+
}
|
|
185
|
+
/** `POST _api/publish` 200 body. */
|
|
186
|
+
export type PublishResponse = PublishResult;
|
|
187
|
+
/** Body of every non-2xx JSON answer. */
|
|
188
|
+
export interface ErrorResponse {
|
|
189
|
+
code: ArtifactErrorCode;
|
|
190
|
+
message: string;
|
|
191
|
+
paths?: ConflictPath[];
|
|
192
|
+
/** Asking again later may succeed (connector calls). */
|
|
193
|
+
retryable?: boolean;
|
|
194
|
+
}
|
|
195
|
+
/** `POST _api/agent/send` request body. */
|
|
196
|
+
export interface AgentSendRequest {
|
|
197
|
+
request: AgentRequest;
|
|
198
|
+
deliver: AgentDelivery;
|
|
199
|
+
}
|
|
200
|
+
/** `POST _api/agent/send` 200 body. */
|
|
201
|
+
export type AgentSendResponse = AgentSendResult;
|
|
202
|
+
/** `POST _api/presence` request body. */
|
|
203
|
+
export interface PresenceRequest {
|
|
204
|
+
client: string;
|
|
205
|
+
patch: Record<string, unknown>;
|
|
206
|
+
}
|
|
207
|
+
/** `GET _api/peers` */
|
|
208
|
+
export interface PeersResponse {
|
|
209
|
+
peers: Peer[];
|
|
210
|
+
}
|
|
211
|
+
/** `GET _api/participants`: the owner, then the people the artifact is shared with. */
|
|
212
|
+
export interface ParticipantsResponse {
|
|
213
|
+
participants: Participant[];
|
|
214
|
+
}
|
|
215
|
+
/** `POST _api/room/emit` request body. Relayed to every other client as a `room` event. */
|
|
216
|
+
export interface RoomEmitRequest {
|
|
217
|
+
client: string;
|
|
218
|
+
topic: string;
|
|
219
|
+
data: JsonValue;
|
|
220
|
+
}
|
|
221
|
+
/** `GET _api/db/get?path=` 200 body. */
|
|
222
|
+
export interface DbGetResponse {
|
|
223
|
+
data: JsonRecord | null;
|
|
224
|
+
}
|
|
225
|
+
/** `GET _api/db/list?collection=` 200 body: `epoch` and `seq` say where the host stood when it read them (older hosts omit them). */
|
|
226
|
+
export interface DbListResponse extends Partial<DbOrder> {
|
|
227
|
+
documents: DbDocument[];
|
|
228
|
+
}
|
|
229
|
+
/** `POST _api/db/write` request body. */
|
|
230
|
+
export interface DbWriteRequest {
|
|
231
|
+
writes: DbWrite[];
|
|
232
|
+
/** The writing page's client id, so the change is not echoed back to it. */
|
|
233
|
+
client: string;
|
|
234
|
+
}
|
|
235
|
+
/** `POST _api/db/write` 200 body: the {@link DbReceipt} (older hosts omit its fields). */
|
|
236
|
+
export interface DbWriteResponse extends Partial<DbReceipt> {
|
|
237
|
+
ok: true;
|
|
238
|
+
}
|
|
239
|
+
/** `GET _api/comments` 200 body, and the body of `POST _api/comments/remove`. */
|
|
240
|
+
export interface CommentsResponse {
|
|
241
|
+
threads: CommentThread[];
|
|
242
|
+
}
|
|
243
|
+
/** `POST _api/comments/create` request body. */
|
|
244
|
+
export interface CommentCreateRequest {
|
|
245
|
+
input: CommentCreate;
|
|
246
|
+
}
|
|
247
|
+
/** `POST _api/comments/reply` request body. */
|
|
248
|
+
export interface CommentReplyRequest {
|
|
249
|
+
threadId: string;
|
|
250
|
+
text: string;
|
|
251
|
+
to?: string[];
|
|
252
|
+
/** The reply assigns the thread to this person (`null`: unassigns it). */
|
|
253
|
+
assignee?: string | null;
|
|
254
|
+
}
|
|
255
|
+
/** `POST _api/comments/edit` request body. */
|
|
256
|
+
export interface CommentEditRequest {
|
|
257
|
+
threadId: string;
|
|
258
|
+
messageId: string;
|
|
259
|
+
text: string;
|
|
260
|
+
to?: string[];
|
|
261
|
+
}
|
|
262
|
+
/** `POST _api/comments/react` request body. */
|
|
263
|
+
export interface CommentReactRequest {
|
|
264
|
+
threadId: string;
|
|
265
|
+
messageId: string;
|
|
266
|
+
emoji: string;
|
|
267
|
+
on: boolean;
|
|
268
|
+
}
|
|
269
|
+
/** `POST _api/comments/resolve` request body. */
|
|
270
|
+
export interface CommentResolveRequest {
|
|
271
|
+
threadId: string;
|
|
272
|
+
resolved: boolean;
|
|
273
|
+
}
|
|
274
|
+
/** `POST _api/comments/move` request body. */
|
|
275
|
+
export interface CommentMoveRequest {
|
|
276
|
+
threadId: string;
|
|
277
|
+
anchor: string;
|
|
278
|
+
location?: JsonRecord;
|
|
279
|
+
/** The anchor the page saw before the move: when given, the server checks the thread is still open there (else 409). */
|
|
280
|
+
from?: string;
|
|
281
|
+
}
|
|
282
|
+
/** `POST _api/comments/remove` request body. */
|
|
283
|
+
export interface CommentRemoveRequest {
|
|
284
|
+
threadId: string;
|
|
285
|
+
messageId?: string;
|
|
286
|
+
}
|
|
287
|
+
/** `POST _api/comments/send` request body. */
|
|
288
|
+
export interface CommentSendRequest {
|
|
289
|
+
threadId: string;
|
|
290
|
+
/** A reply that does not ask the agent, sent because it took part in the thread. */
|
|
291
|
+
unasked?: boolean;
|
|
292
|
+
/** See {@link CommentSendOptions.userText}. */
|
|
293
|
+
userText?: string;
|
|
294
|
+
/** See {@link CommentSendOptions.selectionSnapshot}. */
|
|
295
|
+
selectionSnapshot?: SelectionSnapshot;
|
|
296
|
+
}
|
|
297
|
+
/** 200 body of the comment routes that change one thread. */
|
|
298
|
+
export interface CommentThreadResponse {
|
|
299
|
+
thread: CommentThread;
|
|
300
|
+
}
|
|
301
|
+
/** `GET _api/history` 200 body (versions newest first). */
|
|
302
|
+
export type HistoryResponse = HistoryListing;
|
|
303
|
+
/** `GET _api/history/files?n=` 200 body. */
|
|
304
|
+
export interface HistoryFilesResponse {
|
|
305
|
+
files: FileListing;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* `GET _api/history/file?n=&path=` answers the raw bytes (with
|
|
309
|
+
* {@link SHA_HEADER}); `GET _api/history/diff?n=&path=` a
|
|
310
|
+
* {@link HistoryDiffResponse}.
|
|
311
|
+
*/
|
|
312
|
+
export type HistoryDiffResponse = HistoryFileDiff;
|
|
313
|
+
/** `POST _api/history/restore` request body. */
|
|
314
|
+
export interface HistoryRestoreRequest {
|
|
315
|
+
n: number;
|
|
316
|
+
/** Only these paths (default: every path). */
|
|
317
|
+
paths?: string[];
|
|
318
|
+
/** The restoring page's client id (it hears of the restore like every other page). */
|
|
319
|
+
client?: string;
|
|
320
|
+
}
|
|
321
|
+
/** `POST _api/history/restore` 200 body. */
|
|
322
|
+
export type HistoryRestoreResponse = HistoryRestoreResult;
|
|
323
|
+
/** `POST _api/history/dismiss` request body. */
|
|
324
|
+
export interface HistoryDismissRequest {
|
|
325
|
+
id: string;
|
|
326
|
+
}
|
|
327
|
+
/** `POST _api/history/note` request body: the note on version `n` (`""` removes it). The 200 body is `{ok: true}`. */
|
|
328
|
+
export interface HistoryNoteRequest {
|
|
329
|
+
n: number;
|
|
330
|
+
note: string;
|
|
331
|
+
}
|
|
332
|
+
/** `GET _api/mcp/tools[?server=]` 200 body (the owner only; others get `not_granted`). */
|
|
333
|
+
export interface McpToolsResponse {
|
|
334
|
+
servers: McpServerEntry[];
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* `POST _api/mcp/call` request body (the owner only). The 200 body is the
|
|
338
|
+
* tool's {@link McpToolResult}; failures are an {@link ErrorResponse} with an
|
|
339
|
+
* `McpErrorCode`. Closing the request cancels the call.
|
|
340
|
+
*/
|
|
341
|
+
export interface McpCallRequest {
|
|
342
|
+
server: string;
|
|
343
|
+
tool: string;
|
|
344
|
+
args: Record<string, unknown>;
|
|
345
|
+
/** Default `MCP_CALL_TIMEOUT.defaultMs`. */
|
|
346
|
+
timeoutMs?: number;
|
|
347
|
+
}
|
|
348
|
+
/** `POST _api/mcp/call` 200 body. */
|
|
349
|
+
export type McpCallResponse = McpToolResult;
|
|
350
|
+
/** Server-sent events on `GET _api/events?client=<id>`, by event name. */
|
|
351
|
+
export interface ServerEvents {
|
|
352
|
+
/** Files changed by someone other than the subscribing client. */
|
|
353
|
+
files: FilesChangedEvent;
|
|
354
|
+
/** Agent availability changed. */
|
|
355
|
+
agent: AgentStatus;
|
|
356
|
+
/** The set of present peers changed. */
|
|
357
|
+
peers: Peer[];
|
|
358
|
+
/** Documents changed by someone other than the subscribing client (db-backed types). */
|
|
359
|
+
db: DbChangeEvent;
|
|
360
|
+
/** The full comment thread list, after any change (types with comments). */
|
|
361
|
+
comments: CommentThread[];
|
|
362
|
+
/** An ephemeral message from another client. */
|
|
363
|
+
room: RoomMessage;
|
|
364
|
+
/** A version was recorded (or grew). */
|
|
365
|
+
history: HistoryChangeEvent;
|
|
366
|
+
/** A frame of the workbook's edit log (types with `store: "workbook"`). */
|
|
367
|
+
sheet: SheetFrame;
|
|
368
|
+
/** A walkthrough the agent sent, to one page of the owner's (`SHEET_WALKTHROUGH_EVENT`; types with `store: "workbook"`). */
|
|
369
|
+
sheetWalkthrough: SheetWalkthrough;
|
|
370
|
+
/** A write to a doc, its tabs or its dropdown lists (types with `store: "doc"`). */
|
|
371
|
+
doc: DocFrame;
|
|
372
|
+
}
|
|
373
|
+
export type ServerEventName = keyof ServerEvents;
|
package/src/http-api.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HTTP contract between an editor page and its local type server.
|
|
3
|
+
*
|
|
4
|
+
* Every route is relative to the artifact's page base (for example
|
|
5
|
+
* `http://127.0.0.1:4720/design/<token>/`). Both the browser provider
|
|
6
|
+
* ({@link ./local-provider.ts}) and the Node server (`@openartifactsai/type-server`)
|
|
7
|
+
* import these names and shapes, so the two sides cannot drift apart.
|
|
8
|
+
*/
|
|
9
|
+
/** Route paths, relative to the page base. */
|
|
10
|
+
export const API = {
|
|
11
|
+
session: '_api/session',
|
|
12
|
+
files: '_api/files',
|
|
13
|
+
file: '_api/file',
|
|
14
|
+
publish: '_api/publish',
|
|
15
|
+
assets: '_api/assets',
|
|
16
|
+
events: '_api/events',
|
|
17
|
+
agentSend: '_api/agent/send',
|
|
18
|
+
presence: '_api/presence',
|
|
19
|
+
peers: '_api/peers',
|
|
20
|
+
participants: '_api/participants',
|
|
21
|
+
downloads: '_api/downloads',
|
|
22
|
+
roomEmit: '_api/room/emit',
|
|
23
|
+
dbGet: '_api/db/get',
|
|
24
|
+
dbList: '_api/db/list',
|
|
25
|
+
dbWrite: '_api/db/write',
|
|
26
|
+
comments: '_api/comments',
|
|
27
|
+
commentsCreate: '_api/comments/create',
|
|
28
|
+
commentsReply: '_api/comments/reply',
|
|
29
|
+
commentsEdit: '_api/comments/edit',
|
|
30
|
+
commentsReact: '_api/comments/react',
|
|
31
|
+
commentsResolve: '_api/comments/resolve',
|
|
32
|
+
commentsMove: '_api/comments/move',
|
|
33
|
+
commentsRemove: '_api/comments/remove',
|
|
34
|
+
commentsSend: '_api/comments/send',
|
|
35
|
+
history: '_api/history',
|
|
36
|
+
historyFiles: '_api/history/files',
|
|
37
|
+
historyFile: '_api/history/file',
|
|
38
|
+
historyDiff: '_api/history/diff',
|
|
39
|
+
historyRestore: '_api/history/restore',
|
|
40
|
+
historyDismiss: '_api/history/dismiss',
|
|
41
|
+
historyNote: '_api/history/note',
|
|
42
|
+
systemCopy: '_api/design/system-copy',
|
|
43
|
+
mcpTools: '_api/mcp/tools',
|
|
44
|
+
mcpCall: '_api/mcp/call',
|
|
45
|
+
/**
|
|
46
|
+
* `POST` {@link DataRefreshRequest} → {@link DataRefreshResponse}: a hosted Data dashboard asks its owner's computer to
|
|
47
|
+
* run its live queries again (the host queues it; no connector runs there).
|
|
48
|
+
*/
|
|
49
|
+
dataRefresh: '_api/data/refresh',
|
|
50
|
+
/** `GET` → {@link DataSharesResponse}: the connectors whose access the owner shares on this dashboard. */
|
|
51
|
+
dataShares: '_api/data/shares',
|
|
52
|
+
/** `POST` {@link DataShareRequest} → {@link DataShareResponse}: the owner shares (or, with no calls, stops sharing) a connector. */
|
|
53
|
+
dataShare: '_api/data/share',
|
|
54
|
+
/** `POST` {@link DataSharedRequest} → {@link DataSharedResponse}: runs approved calls with the sharer's connector. */
|
|
55
|
+
dataShared: '_api/data/shared',
|
|
56
|
+
/**
|
|
57
|
+
* `POST` {@link FrameSampleRequest} (`client`: the page's id): one `sample` call of the editor, answered as an NDJSON
|
|
58
|
+
* stream of `SampleStreamEvent`s until `done` or `error` (a refusal is one `error` line). Closing the request cancels
|
|
59
|
+
* the call. The owner only, on this computer.
|
|
60
|
+
*/
|
|
61
|
+
sample: '_api/sample',
|
|
62
|
+
/** `POST` {@link FrameSampleToolRequest}: one round's tool results; answers `{ok: true}` or `{error}`. */
|
|
63
|
+
sampleTool: '_api/sample/tool',
|
|
64
|
+
/** `GET ?client=` → `SampleLimits`, or `{error}`. */
|
|
65
|
+
sampleLimits: '_api/sample/limits',
|
|
66
|
+
/** `GET` → {@link SampleStateResponse}: whether a call would go ahead without a consent dialog. */
|
|
67
|
+
sampleState: '_api/sample/state',
|
|
68
|
+
};
|
|
69
|
+
/** Root-relative prefix every upload is served under. */
|
|
70
|
+
export const BLOB_PREFIX = '/_blob/';
|
|
71
|
+
/** Header carrying the SHA-256 of a file returned by `GET _api/file`. */
|
|
72
|
+
export const SHA_HEADER = 'x-open-artifacts-sha256';
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@openartifactsai/runtime`: the `window.openartifacts` page runtime.
|
|
3
|
+
*
|
|
4
|
+
* - `capabilities.ts`: the capability contracts (types and errors).
|
|
5
|
+
* - `client.ts`: installs `window.openartifacts` over a provider.
|
|
6
|
+
* - `local-provider.ts`: the provider backed by the local type server.
|
|
7
|
+
* - `broker.ts`: the provider that brokers calls through the Shell (and `createPageProvider`).
|
|
8
|
+
* - `http-api.ts`: the HTTP contract shared with `@openartifactsai/type-server`.
|
|
9
|
+
* - `sheet-api.ts`: the `sheet` capability's own routes and frames.
|
|
10
|
+
* - `doc-api.ts`: the Docs type's HTTP contract (the `doc` capability).
|
|
11
|
+
* - `shell.ts`: the page side of the Open Artifacts Shell protocol.
|
|
12
|
+
* - `untrusted.ts`: fencing untrusted text before it reaches a model.
|
|
13
|
+
* - `sample.ts`: the `sample` capability (asking the person's model) and its transports.
|
|
14
|
+
*/
|
|
15
|
+
export * from './capabilities.js';
|
|
16
|
+
export * from './client.js';
|
|
17
|
+
export * from './local-provider.js';
|
|
18
|
+
export * from './broker.js';
|
|
19
|
+
export * from './http-api.js';
|
|
20
|
+
export * from './sheet-api.js';
|
|
21
|
+
export * from './doc-api.js';
|
|
22
|
+
export * from './shell.js';
|
|
23
|
+
export * from './untrusted.js';
|
|
24
|
+
export * from './sample.js';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@openartifactsai/runtime`: the `window.openartifacts` page runtime.
|
|
3
|
+
*
|
|
4
|
+
* - `capabilities.ts`: the capability contracts (types and errors).
|
|
5
|
+
* - `client.ts`: installs `window.openartifacts` over a provider.
|
|
6
|
+
* - `local-provider.ts`: the provider backed by the local type server.
|
|
7
|
+
* - `broker.ts`: the provider that brokers calls through the Shell (and `createPageProvider`).
|
|
8
|
+
* - `http-api.ts`: the HTTP contract shared with `@openartifactsai/type-server`.
|
|
9
|
+
* - `sheet-api.ts`: the `sheet` capability's own routes and frames.
|
|
10
|
+
* - `doc-api.ts`: the Docs type's HTTP contract (the `doc` capability).
|
|
11
|
+
* - `shell.ts`: the page side of the Open Artifacts Shell protocol.
|
|
12
|
+
* - `untrusted.ts`: fencing untrusted text before it reaches a model.
|
|
13
|
+
* - `sample.ts`: the `sample` capability (asking the person's model) and its transports.
|
|
14
|
+
*/
|
|
15
|
+
export * from "./capabilities.js";
|
|
16
|
+
export * from "./client.js";
|
|
17
|
+
export * from "./local-provider.js";
|
|
18
|
+
export * from "./broker.js";
|
|
19
|
+
export * from "./http-api.js";
|
|
20
|
+
export * from "./sheet-api.js";
|
|
21
|
+
export * from "./doc-api.js";
|
|
22
|
+
export * from "./shell.js";
|
|
23
|
+
export * from "./untrusted.js";
|
|
24
|
+
export * from "./sample.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Imported first by an editor's entry, for its side effect: values an editor from before the rename kept in this
|
|
3
|
+
* origin's `localStorage` and `sessionStorage` (`open-artifact…` keys) move to their `open-artifacts…` keys before any
|
|
4
|
+
* module reads them (`adoptLegacyBrowserStorage`).
|
|
5
|
+
*/
|
|
6
|
+
import { adoptLegacyBrowserStorage } from '@openartifactsai/protocol/legacy-wire';
|
|
7
|
+
adoptLegacyBrowserStorage();
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A capability provider backed by the local type server's HTTP API.
|
|
3
|
+
*
|
|
4
|
+
* This is what makes an editor page work when it is served by
|
|
5
|
+
* `@openartifactsai/type-server`: every capability call becomes a `fetch`
|
|
6
|
+
* against the page base, and pushed changes arrive over one EventSource.
|
|
7
|
+
*/
|
|
8
|
+
import type { CapabilityProvider } from './client.js';
|
|
9
|
+
/**
|
|
10
|
+
* Why the page's access changed: `removed` (the server now refuses this
|
|
11
|
+
* viewer: a share link was turned off or reset, the guest was removed, or
|
|
12
|
+
* sharing stopped) or `changed` (the viewer is someone else now, or has
|
|
13
|
+
* another role).
|
|
14
|
+
*/
|
|
15
|
+
export type AccessChange = 'removed' | 'changed';
|
|
16
|
+
/** Options of {@link createLocalProvider}. */
|
|
17
|
+
export interface LocalProviderOptions {
|
|
18
|
+
/** The page base URL; defaults to the directory of `location.href`. */
|
|
19
|
+
base?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Called once when the event stream was cut and the server no longer lets
|
|
22
|
+
* this viewer in as before (instead of reconnecting forever). Default:
|
|
23
|
+
* reload the page, so it opens with the new role, or the server's
|
|
24
|
+
* "No access" page.
|
|
25
|
+
*/
|
|
26
|
+
onAccessChange?: (change: AccessChange) => void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* What a session answer means for a page that started as `was`: `null` when
|
|
30
|
+
* nothing changed, else how its access changed. `status` is the HTTP status
|
|
31
|
+
* of `_api/session`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function accessChangeOf(was: {
|
|
34
|
+
id: string;
|
|
35
|
+
role: string;
|
|
36
|
+
}, status: number, now?: {
|
|
37
|
+
id?: unknown;
|
|
38
|
+
role?: unknown;
|
|
39
|
+
} | null): AccessChange | null;
|
|
40
|
+
/**
|
|
41
|
+
* Creates the provider. Capabilities are built lazily on first `use()` and the
|
|
42
|
+
* session (`GET _api/session`) is fetched once and shared.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createLocalProvider(options?: LocalProviderOptions): CapabilityProvider;
|