@open-artifact/runtime 0.0.0-stage → 0.2.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 +48 -4
- package/src/broker.d.ts +83 -0
- package/src/broker.js +352 -0
- package/src/capabilities.d.ts +629 -0
- package/src/capabilities.js +73 -0
- package/src/client.d.ts +29 -0
- package/src/client.js +64 -0
- package/src/http-api.d.ts +216 -0
- package/src/http-api.js +44 -0
- package/src/index.d.ts +18 -0
- package/src/index.js +18 -0
- package/src/local-provider.d.ts +44 -0
- package/src/local-provider.js +388 -0
- package/src/shell.d.ts +46 -0
- package/src/shell.js +113 -0
- package/src/untrusted.d.ts +24 -0
- package/src/untrusted.js +35 -0
package/src/client.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Installs `window.openartifact` 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 OpenArtifactRuntime } from './capabilities.ts';
|
|
11
|
+
/** Something that can produce capability namespaces. */
|
|
12
|
+
export interface CapabilityProvider {
|
|
13
|
+
/** Returns the namespace, or `null` when this view may not use it. */
|
|
14
|
+
get<K extends CapabilityName>(name: K): Promise<CapabilityMap[K] | null> | CapabilityMap[K] | null;
|
|
15
|
+
}
|
|
16
|
+
/** Options of {@link createRuntime}. */
|
|
17
|
+
export interface RuntimeOptions {
|
|
18
|
+
/** Milliseconds before an unanswered `use()` resolves to `null`. Default 10 000. */
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
}
|
|
21
|
+
/** Builds a runtime object without installing it globally. */
|
|
22
|
+
export declare function createRuntime(provider: CapabilityProvider, options?: RuntimeOptions): OpenArtifactRuntime;
|
|
23
|
+
/**
|
|
24
|
+
* Installs the runtime at `window.openartifact` (once) and returns it.
|
|
25
|
+
* A runtime already installed by the host wins: pages call this defensively.
|
|
26
|
+
*/
|
|
27
|
+
export declare function installRuntime(provider: CapabilityProvider, options?: RuntimeOptions): OpenArtifactRuntime;
|
|
28
|
+
/** Shortcut for `window.openartifact?.use(name)` that never throws. */
|
|
29
|
+
export declare function useCapability<K extends CapabilityName>(name: K): Promise<CapabilityMap[K] | null>;
|
package/src/client.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Installs `window.openartifact` 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 { CONTRACT_VERSION, } from "./capabilities.js";
|
|
11
|
+
/** Builds a runtime object without installing it globally. */
|
|
12
|
+
export function createRuntime(provider, options = {}) {
|
|
13
|
+
const timeoutMs = options.timeoutMs ?? 10_000;
|
|
14
|
+
const cache = new Map();
|
|
15
|
+
const use = (name) => {
|
|
16
|
+
const cached = cache.get(name);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
const pending = new Promise((resolve) => {
|
|
20
|
+
const timer = setTimeout(() => resolve(null), timeoutMs);
|
|
21
|
+
Promise.resolve()
|
|
22
|
+
.then(() => provider.get(name))
|
|
23
|
+
.then((namespace) => {
|
|
24
|
+
clearTimeout(timer);
|
|
25
|
+
resolve(namespace ? Object.freeze(namespace) : null);
|
|
26
|
+
}, () => {
|
|
27
|
+
clearTimeout(timer);
|
|
28
|
+
resolve(null);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
cache.set(name, pending);
|
|
32
|
+
return pending;
|
|
33
|
+
};
|
|
34
|
+
return Object.freeze({ version: CONTRACT_VERSION, use });
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Installs the runtime at `window.openartifact` (once) and returns it.
|
|
38
|
+
* A runtime already installed by the host wins: pages call this defensively.
|
|
39
|
+
*/
|
|
40
|
+
export function installRuntime(provider, options) {
|
|
41
|
+
const existing = globalThis.window?.openartifact;
|
|
42
|
+
if (existing)
|
|
43
|
+
return existing;
|
|
44
|
+
const runtime = createRuntime(provider, options);
|
|
45
|
+
Object.defineProperty(window, 'openartifact', {
|
|
46
|
+
value: runtime,
|
|
47
|
+
configurable: false,
|
|
48
|
+
enumerable: true,
|
|
49
|
+
writable: false,
|
|
50
|
+
});
|
|
51
|
+
return runtime;
|
|
52
|
+
}
|
|
53
|
+
/** Shortcut for `window.openartifact?.use(name)` that never throws. */
|
|
54
|
+
export async function useCapability(name) {
|
|
55
|
+
const runtime = globalThis.window?.openartifact;
|
|
56
|
+
if (!runtime)
|
|
57
|
+
return null;
|
|
58
|
+
try {
|
|
59
|
+
return await runtime.use(name);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
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 (`@open-artifact/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, DbWrite, FileListing, FilesChangedEvent, HistoryChangeEvent, HistoryFileDiff, HistoryListing, HistoryRestoreResult, JsonRecord, JsonValue, McpServerEntry, McpToolResult, Peer, PublishBatch, PublishResult, RoomMessage, Viewer } from './capabilities.ts';
|
|
10
|
+
/** Route paths, relative to the page base. */
|
|
11
|
+
export declare const API: {
|
|
12
|
+
readonly session: "_api/session";
|
|
13
|
+
readonly files: "_api/files";
|
|
14
|
+
readonly file: "_api/file";
|
|
15
|
+
readonly publish: "_api/publish";
|
|
16
|
+
readonly assets: "_api/assets";
|
|
17
|
+
readonly events: "_api/events";
|
|
18
|
+
readonly agentSend: "_api/agent/send";
|
|
19
|
+
readonly presence: "_api/presence";
|
|
20
|
+
readonly peers: "_api/peers";
|
|
21
|
+
readonly downloads: "_api/downloads";
|
|
22
|
+
readonly roomEmit: "_api/room/emit";
|
|
23
|
+
readonly dbGet: "_api/db/get";
|
|
24
|
+
readonly dbList: "_api/db/list";
|
|
25
|
+
readonly dbWrite: "_api/db/write";
|
|
26
|
+
readonly comments: "_api/comments";
|
|
27
|
+
readonly commentsCreate: "_api/comments/create";
|
|
28
|
+
readonly commentsReply: "_api/comments/reply";
|
|
29
|
+
readonly commentsResolve: "_api/comments/resolve";
|
|
30
|
+
readonly commentsMove: "_api/comments/move";
|
|
31
|
+
readonly commentsRemove: "_api/comments/remove";
|
|
32
|
+
readonly commentsSend: "_api/comments/send";
|
|
33
|
+
readonly history: "_api/history";
|
|
34
|
+
readonly historyFiles: "_api/history/files";
|
|
35
|
+
readonly historyFile: "_api/history/file";
|
|
36
|
+
readonly historyDiff: "_api/history/diff";
|
|
37
|
+
readonly historyRestore: "_api/history/restore";
|
|
38
|
+
readonly historyDismiss: "_api/history/dismiss";
|
|
39
|
+
readonly mcpTools: "_api/mcp/tools";
|
|
40
|
+
readonly mcpCall: "_api/mcp/call";
|
|
41
|
+
};
|
|
42
|
+
/** Root-relative prefix every upload is served under. */
|
|
43
|
+
export declare const BLOB_PREFIX = "/_blob/";
|
|
44
|
+
/** `GET _api/session` */
|
|
45
|
+
export interface SessionResponse {
|
|
46
|
+
artifact: {
|
|
47
|
+
id: string;
|
|
48
|
+
title: string;
|
|
49
|
+
type: string;
|
|
50
|
+
};
|
|
51
|
+
viewer: Viewer;
|
|
52
|
+
agent: AgentStatus;
|
|
53
|
+
/** Stores the type keeps beside its files; absent ones are not offered (`db` / `comments` resolve `null`). */
|
|
54
|
+
stores?: {
|
|
55
|
+
db?: boolean;
|
|
56
|
+
comments?: boolean;
|
|
57
|
+
history?: boolean;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** `GET _api/files` */
|
|
61
|
+
export interface FilesResponse {
|
|
62
|
+
files: FileListing;
|
|
63
|
+
}
|
|
64
|
+
/** Header carrying the SHA-256 of a file returned by `GET _api/file`. */
|
|
65
|
+
export declare const SHA_HEADER = "x-open-artifact-sha256";
|
|
66
|
+
/** `POST _api/publish` request body. */
|
|
67
|
+
export interface PublishRequest {
|
|
68
|
+
files: PublishBatch;
|
|
69
|
+
/** The publishing page's client id, so its own change events are not echoed back. */
|
|
70
|
+
client: string;
|
|
71
|
+
}
|
|
72
|
+
/** `POST _api/publish` 200 body. */
|
|
73
|
+
export type PublishResponse = PublishResult;
|
|
74
|
+
/** Body of every non-2xx JSON answer. */
|
|
75
|
+
export interface ErrorResponse {
|
|
76
|
+
code: ArtifactErrorCode;
|
|
77
|
+
message: string;
|
|
78
|
+
paths?: ConflictPath[];
|
|
79
|
+
/** Asking again later may succeed (connector calls). */
|
|
80
|
+
retryable?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/** `POST _api/agent/send` request body. */
|
|
83
|
+
export interface AgentSendRequest {
|
|
84
|
+
request: AgentRequest;
|
|
85
|
+
deliver: AgentDelivery;
|
|
86
|
+
}
|
|
87
|
+
/** `POST _api/agent/send` 200 body. */
|
|
88
|
+
export type AgentSendResponse = AgentSendResult;
|
|
89
|
+
/** `POST _api/presence` request body. */
|
|
90
|
+
export interface PresenceRequest {
|
|
91
|
+
client: string;
|
|
92
|
+
patch: Record<string, unknown>;
|
|
93
|
+
}
|
|
94
|
+
/** `GET _api/peers` */
|
|
95
|
+
export interface PeersResponse {
|
|
96
|
+
peers: Peer[];
|
|
97
|
+
}
|
|
98
|
+
/** `POST _api/room/emit` request body. Relayed to every other client as a `room` event. */
|
|
99
|
+
export interface RoomEmitRequest {
|
|
100
|
+
client: string;
|
|
101
|
+
topic: string;
|
|
102
|
+
data: JsonValue;
|
|
103
|
+
}
|
|
104
|
+
/** `GET _api/db/get?path=` 200 body. */
|
|
105
|
+
export interface DbGetResponse {
|
|
106
|
+
data: JsonRecord | null;
|
|
107
|
+
}
|
|
108
|
+
/** `GET _api/db/list?collection=` 200 body. */
|
|
109
|
+
export interface DbListResponse {
|
|
110
|
+
documents: DbDocument[];
|
|
111
|
+
}
|
|
112
|
+
/** `POST _api/db/write` request body. */
|
|
113
|
+
export interface DbWriteRequest {
|
|
114
|
+
writes: DbWrite[];
|
|
115
|
+
/** The writing page's client id, so the change is not echoed back to it. */
|
|
116
|
+
client: string;
|
|
117
|
+
}
|
|
118
|
+
/** `GET _api/comments` 200 body, and the body of `POST _api/comments/remove`. */
|
|
119
|
+
export interface CommentsResponse {
|
|
120
|
+
threads: CommentThread[];
|
|
121
|
+
}
|
|
122
|
+
/** `POST _api/comments/create` request body. */
|
|
123
|
+
export interface CommentCreateRequest {
|
|
124
|
+
input: CommentCreate;
|
|
125
|
+
}
|
|
126
|
+
/** `POST _api/comments/reply` request body. */
|
|
127
|
+
export interface CommentReplyRequest {
|
|
128
|
+
threadId: string;
|
|
129
|
+
text: string;
|
|
130
|
+
}
|
|
131
|
+
/** `POST _api/comments/resolve` request body. */
|
|
132
|
+
export interface CommentResolveRequest {
|
|
133
|
+
threadId: string;
|
|
134
|
+
resolved: boolean;
|
|
135
|
+
}
|
|
136
|
+
/** `POST _api/comments/move` request body. */
|
|
137
|
+
export interface CommentMoveRequest {
|
|
138
|
+
threadId: string;
|
|
139
|
+
anchor: string;
|
|
140
|
+
location?: JsonRecord;
|
|
141
|
+
}
|
|
142
|
+
/** `POST _api/comments/remove` request body. */
|
|
143
|
+
export interface CommentRemoveRequest {
|
|
144
|
+
threadId: string;
|
|
145
|
+
messageId?: string;
|
|
146
|
+
}
|
|
147
|
+
/** `POST _api/comments/send` request body. */
|
|
148
|
+
export interface CommentSendRequest {
|
|
149
|
+
threadId: string;
|
|
150
|
+
}
|
|
151
|
+
/** 200 body of the comment routes that change one thread. */
|
|
152
|
+
export interface CommentThreadResponse {
|
|
153
|
+
thread: CommentThread;
|
|
154
|
+
}
|
|
155
|
+
/** `GET _api/history` 200 body (versions newest first). */
|
|
156
|
+
export type HistoryResponse = HistoryListing;
|
|
157
|
+
/** `GET _api/history/files?n=` 200 body. */
|
|
158
|
+
export interface HistoryFilesResponse {
|
|
159
|
+
files: FileListing;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* `GET _api/history/file?n=&path=` answers the raw bytes (with
|
|
163
|
+
* {@link SHA_HEADER}); `GET _api/history/diff?n=&path=` a
|
|
164
|
+
* {@link HistoryDiffResponse}.
|
|
165
|
+
*/
|
|
166
|
+
export type HistoryDiffResponse = HistoryFileDiff;
|
|
167
|
+
/** `POST _api/history/restore` request body. */
|
|
168
|
+
export interface HistoryRestoreRequest {
|
|
169
|
+
n: number;
|
|
170
|
+
/** Only these paths (default: every path). */
|
|
171
|
+
paths?: string[];
|
|
172
|
+
/** The restoring page's client id (it hears of the restore like every other page). */
|
|
173
|
+
client?: string;
|
|
174
|
+
}
|
|
175
|
+
/** `POST _api/history/restore` 200 body. */
|
|
176
|
+
export type HistoryRestoreResponse = HistoryRestoreResult;
|
|
177
|
+
/** `POST _api/history/dismiss` request body. */
|
|
178
|
+
export interface HistoryDismissRequest {
|
|
179
|
+
id: string;
|
|
180
|
+
}
|
|
181
|
+
/** `GET _api/mcp/tools[?server=]` 200 body (the owner only; others get `not_granted`). */
|
|
182
|
+
export interface McpToolsResponse {
|
|
183
|
+
servers: McpServerEntry[];
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* `POST _api/mcp/call` request body (the owner only). The 200 body is the
|
|
187
|
+
* tool's {@link McpToolResult}; failures are an {@link ErrorResponse} with an
|
|
188
|
+
* `McpErrorCode`. Closing the request cancels the call.
|
|
189
|
+
*/
|
|
190
|
+
export interface McpCallRequest {
|
|
191
|
+
server: string;
|
|
192
|
+
tool: string;
|
|
193
|
+
args: Record<string, unknown>;
|
|
194
|
+
/** Default `MCP_CALL_TIMEOUT.defaultMs`. */
|
|
195
|
+
timeoutMs?: number;
|
|
196
|
+
}
|
|
197
|
+
/** `POST _api/mcp/call` 200 body. */
|
|
198
|
+
export type McpCallResponse = McpToolResult;
|
|
199
|
+
/** Server-sent events on `GET _api/events?client=<id>`, by event name. */
|
|
200
|
+
export interface ServerEvents {
|
|
201
|
+
/** Files changed by someone other than the subscribing client. */
|
|
202
|
+
files: FilesChangedEvent;
|
|
203
|
+
/** Agent availability changed. */
|
|
204
|
+
agent: AgentStatus;
|
|
205
|
+
/** The set of present peers changed. */
|
|
206
|
+
peers: Peer[];
|
|
207
|
+
/** Documents changed by someone other than the subscribing client (db-backed types). */
|
|
208
|
+
db: DbChangeEvent;
|
|
209
|
+
/** The full comment thread list, after any change (types with comments). */
|
|
210
|
+
comments: CommentThread[];
|
|
211
|
+
/** An ephemeral message from another client. */
|
|
212
|
+
room: RoomMessage;
|
|
213
|
+
/** A version was recorded (or grew). */
|
|
214
|
+
history: HistoryChangeEvent;
|
|
215
|
+
}
|
|
216
|
+
export type ServerEventName = keyof ServerEvents;
|
package/src/http-api.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
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 (`@open-artifact/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
|
+
downloads: '_api/downloads',
|
|
21
|
+
roomEmit: '_api/room/emit',
|
|
22
|
+
dbGet: '_api/db/get',
|
|
23
|
+
dbList: '_api/db/list',
|
|
24
|
+
dbWrite: '_api/db/write',
|
|
25
|
+
comments: '_api/comments',
|
|
26
|
+
commentsCreate: '_api/comments/create',
|
|
27
|
+
commentsReply: '_api/comments/reply',
|
|
28
|
+
commentsResolve: '_api/comments/resolve',
|
|
29
|
+
commentsMove: '_api/comments/move',
|
|
30
|
+
commentsRemove: '_api/comments/remove',
|
|
31
|
+
commentsSend: '_api/comments/send',
|
|
32
|
+
history: '_api/history',
|
|
33
|
+
historyFiles: '_api/history/files',
|
|
34
|
+
historyFile: '_api/history/file',
|
|
35
|
+
historyDiff: '_api/history/diff',
|
|
36
|
+
historyRestore: '_api/history/restore',
|
|
37
|
+
historyDismiss: '_api/history/dismiss',
|
|
38
|
+
mcpTools: '_api/mcp/tools',
|
|
39
|
+
mcpCall: '_api/mcp/call',
|
|
40
|
+
};
|
|
41
|
+
/** Root-relative prefix every upload is served under. */
|
|
42
|
+
export const BLOB_PREFIX = '/_blob/';
|
|
43
|
+
/** Header carrying the SHA-256 of a file returned by `GET _api/file`. */
|
|
44
|
+
export const SHA_HEADER = 'x-open-artifact-sha256';
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@open-artifact/runtime`: the `window.openartifact` page runtime.
|
|
3
|
+
*
|
|
4
|
+
* - `capabilities.ts`: the capability contracts (types and errors).
|
|
5
|
+
* - `client.ts`: installs `window.openartifact` 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 `@open-artifact/type-server`.
|
|
9
|
+
* - `shell.ts`: the page side of the Open Artifact Shell protocol.
|
|
10
|
+
* - `untrusted.ts`: fencing untrusted text before it reaches a model.
|
|
11
|
+
*/
|
|
12
|
+
export * from './capabilities.ts';
|
|
13
|
+
export * from './client.ts';
|
|
14
|
+
export * from './local-provider.ts';
|
|
15
|
+
export * from './broker.ts';
|
|
16
|
+
export * from './http-api.ts';
|
|
17
|
+
export * from './shell.ts';
|
|
18
|
+
export * from './untrusted.ts';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@open-artifact/runtime`: the `window.openartifact` page runtime.
|
|
3
|
+
*
|
|
4
|
+
* - `capabilities.ts`: the capability contracts (types and errors).
|
|
5
|
+
* - `client.ts`: installs `window.openartifact` 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 `@open-artifact/type-server`.
|
|
9
|
+
* - `shell.ts`: the page side of the Open Artifact Shell protocol.
|
|
10
|
+
* - `untrusted.ts`: fencing untrusted text before it reaches a model.
|
|
11
|
+
*/
|
|
12
|
+
export * from "./capabilities.js";
|
|
13
|
+
export * from "./client.js";
|
|
14
|
+
export * from "./local-provider.js";
|
|
15
|
+
export * from "./broker.js";
|
|
16
|
+
export * from "./http-api.js";
|
|
17
|
+
export * from "./shell.js";
|
|
18
|
+
export * from "./untrusted.js";
|
|
@@ -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
|
+
* `@open-artifact/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.ts';
|
|
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;
|