@bendyline/gezel-sdk 0.1.0 → 1.0.1
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/dist/page.d.ts +224 -0
- package/dist/page.js +5 -0
- package/package.json +6 -2
package/dist/page.d.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@bendyline/gezel-sdk/page` — the Output Pane API v1 typing contract for
|
|
3
|
+
* `window.gezel`, the object every served project-type page codes against.
|
|
4
|
+
*
|
|
5
|
+
* The runtime object is injected server-side by the daemon
|
|
6
|
+
* (`packages/service/src/http/routes/page-api-shim.ts` splices the shim
|
|
7
|
+
* into every `text/html` response served from the `type` preview source),
|
|
8
|
+
* so pages never bundle an implementation — this module exists so gilde
|
|
9
|
+
* page authors and the host UI relay share one contract. The postMessage
|
|
10
|
+
* envelope behind it is validated by the zod schemas in
|
|
11
|
+
* `@bendyline/gezel` (`packages/core/src/schemas/page-bridge.ts`); the
|
|
12
|
+
* shapes here are mirrored, not imported, for the same reason as
|
|
13
|
+
* `./types.ts` — the SDK stays runtime-dependency-free and vendor-friendly.
|
|
14
|
+
*
|
|
15
|
+
* Modes and what degrades outside the app:
|
|
16
|
+
* - `embedded` — the Output pane iframe. Every call relays over the v1
|
|
17
|
+
* postMessage envelope to the host, which holds the credentials; the
|
|
18
|
+
* page never sees one.
|
|
19
|
+
* - `browser` — an "Open in browser" tab with no embedding parent. Data
|
|
20
|
+
* reads fall back to same-origin capability fetches; `tools.invoke`
|
|
21
|
+
* rejects with code `'unavailable'`; `refresh()` reloads the page.
|
|
22
|
+
* - `demo` — a raw file opened outside gezel entirely. The real shim is
|
|
23
|
+
* never present there; gilde ships a paste-in stub that defines
|
|
24
|
+
* `window.gezel` only when the real one is absent.
|
|
25
|
+
*
|
|
26
|
+
* Guard accordingly: `if (window.gezel) { ... }`.
|
|
27
|
+
*/
|
|
28
|
+
/** The page-API generation this module types. Compare with `page.api`. */
|
|
29
|
+
declare const GEZEL_PAGE_API_VERSION: 1;
|
|
30
|
+
/**
|
|
31
|
+
* Where a data call reads from: the project's editable `workspace` tree
|
|
32
|
+
* or its generated-output `artifacts` store. Defaults to `'workspace'`.
|
|
33
|
+
* Reads are scoped server-side to what the page's manifest declared —
|
|
34
|
+
* out-of-scope paths reject with code `'not-allowed'`.
|
|
35
|
+
*/
|
|
36
|
+
type GezelPageReadSource = 'workspace' | 'artifacts';
|
|
37
|
+
/** How the page is being viewed; see the module doc for what each mode degrades. */
|
|
38
|
+
type GezelPageMode = 'embedded' | 'browser' | 'demo';
|
|
39
|
+
/** Error codes a rejected page-API call carries (`GezelPageError.code`). */
|
|
40
|
+
type GezelPageErrorCode = 'not-allowed' | 'invalid-input' | 'script-error' | 'timeout' | 'unavailable' | 'rate-limited';
|
|
41
|
+
/**
|
|
42
|
+
* The error every page-API rejection carries. `code` is the stable field
|
|
43
|
+
* to branch on; `message` is human-readable and may change between
|
|
44
|
+
* releases.
|
|
45
|
+
*/
|
|
46
|
+
interface GezelPageError extends Error {
|
|
47
|
+
/** Machine-readable failure class. */
|
|
48
|
+
code: GezelPageErrorCode;
|
|
49
|
+
/** The script run that failed, when a tool invoke got far enough to start one. */
|
|
50
|
+
runId?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Static facts about this page, baked in at serve time — the daemon is
|
|
54
|
+
* authoritative, so pages never derive identity from their own URL.
|
|
55
|
+
*/
|
|
56
|
+
interface GezelPageInfo {
|
|
57
|
+
/** Page-API generation; `1` for this contract. */
|
|
58
|
+
api: 1;
|
|
59
|
+
/** The project this page is served for. */
|
|
60
|
+
projectId: string;
|
|
61
|
+
/** Always `'type'` — pages are served from an installed project type. */
|
|
62
|
+
source: 'type';
|
|
63
|
+
/** Entry path relative to the type version's pages/ tree, e.g. `'board/index.html'`. */
|
|
64
|
+
entry: string;
|
|
65
|
+
/** Name of the project type that shipped this page. */
|
|
66
|
+
typeName: string;
|
|
67
|
+
/** The project's adoption params (the values chosen when the type was adopted). */
|
|
68
|
+
params: Record<string, unknown>;
|
|
69
|
+
/** How the page is currently being viewed. */
|
|
70
|
+
mode: GezelPageMode;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Whether a gezel picked up the side effects of a tool invoke (e.g. a
|
|
74
|
+
* record change a crew member should react to), and why not when not.
|
|
75
|
+
*/
|
|
76
|
+
interface GezelPageToolReaction {
|
|
77
|
+
/** `true` when the reaction was handed to a gezel. */
|
|
78
|
+
delivered: boolean;
|
|
79
|
+
/** The gezel it was delivered to, when known. */
|
|
80
|
+
gezelId?: string;
|
|
81
|
+
/** Why delivery was skipped, when it was. */
|
|
82
|
+
reason?: string;
|
|
83
|
+
}
|
|
84
|
+
/** Resolution value of {@link GezelPageToolsApi.invoke}. */
|
|
85
|
+
interface GezelPageToolResult {
|
|
86
|
+
/** The value the tool's script stamped as its output. */
|
|
87
|
+
output: unknown;
|
|
88
|
+
/** The script run that produced the output, for correlating logs. */
|
|
89
|
+
runId?: string;
|
|
90
|
+
/** Gezel-reaction delivery status, when the tool declared one. */
|
|
91
|
+
reaction?: GezelPageToolReaction;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Project-type tools the page may invoke. Only tools the type's manifest
|
|
95
|
+
* declared page-invokable are callable — everything else rejects with
|
|
96
|
+
* code `'not-allowed'`.
|
|
97
|
+
*/
|
|
98
|
+
interface GezelPageToolsApi {
|
|
99
|
+
/** Names of the tools this page may invoke (a fresh copy per call). */
|
|
100
|
+
list(): string[];
|
|
101
|
+
/**
|
|
102
|
+
* Invoke a declared tool and await its output. Rejects with a
|
|
103
|
+
* {@link GezelPageError} (`'unavailable'` outside the app,
|
|
104
|
+
* `'timeout'` when the run outlives the call budget, `'rate-limited'`
|
|
105
|
+
* when too many calls are queued).
|
|
106
|
+
*
|
|
107
|
+
* @param tool - Tool name, as returned by {@link list}.
|
|
108
|
+
* @param input - Tool input object; validated against the tool's declared inputs.
|
|
109
|
+
*/
|
|
110
|
+
invoke(tool: string, input?: Record<string, unknown>): Promise<GezelPageToolResult>;
|
|
111
|
+
}
|
|
112
|
+
/** Options for {@link GezelPageDataApi.read}. */
|
|
113
|
+
interface GezelPageReadOptions {
|
|
114
|
+
/** Which tree to read from. Defaults to `'workspace'`. */
|
|
115
|
+
source?: GezelPageReadSource;
|
|
116
|
+
/**
|
|
117
|
+
* Decode as `'text'` (string), `'json'` (parsed value), or `'bytes'`
|
|
118
|
+
* (Uint8Array). Default derives from the extension: `.json` files parse
|
|
119
|
+
* as JSON, everything else reads as text.
|
|
120
|
+
*/
|
|
121
|
+
as?: 'text' | 'json' | 'bytes';
|
|
122
|
+
/** Reject reads larger than this many bytes (host ceilings still apply). */
|
|
123
|
+
maxBytes?: number;
|
|
124
|
+
}
|
|
125
|
+
/** Options for {@link GezelPageDataApi.list} and {@link GezelPageDataApi.url}. */
|
|
126
|
+
interface GezelPageSourceOptions {
|
|
127
|
+
/** Which tree to target. Defaults to `'workspace'`. */
|
|
128
|
+
source?: GezelPageReadSource;
|
|
129
|
+
}
|
|
130
|
+
/** One entry of a directory listing. */
|
|
131
|
+
interface GezelPageDirEntry {
|
|
132
|
+
/** Base name of the entry (not the full path). */
|
|
133
|
+
name: string;
|
|
134
|
+
kind: 'file' | 'dir';
|
|
135
|
+
/** Size in bytes; `0` for directories. */
|
|
136
|
+
size: number;
|
|
137
|
+
/** Last-modified time, milliseconds since the epoch. */
|
|
138
|
+
mtime: number;
|
|
139
|
+
}
|
|
140
|
+
/** The change notification a watch callback receives. */
|
|
141
|
+
interface GezelPageWatchEvent {
|
|
142
|
+
/** The watched path (as passed to `watch`). */
|
|
143
|
+
path: string;
|
|
144
|
+
/** Opaque content stamp; changes whenever the content does. Re-read to get the new value. */
|
|
145
|
+
etag: string;
|
|
146
|
+
}
|
|
147
|
+
/** Options for {@link GezelPageDataApi.watch}. */
|
|
148
|
+
interface GezelPageWatchOptions {
|
|
149
|
+
/** Which tree the watched path lives in. Defaults to `'workspace'`. */
|
|
150
|
+
source?: GezelPageReadSource;
|
|
151
|
+
/** Poll interval for browser-mode fallback polling; embedded watches push and ignore it. */
|
|
152
|
+
intervalMs?: number;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Read-only access to the project's files, scoped to what the page's
|
|
156
|
+
* manifest declared readable. Out-of-scope paths reject with code
|
|
157
|
+
* `'not-allowed'`; writes happen through {@link GezelPageToolsApi} only.
|
|
158
|
+
*/
|
|
159
|
+
interface GezelPageDataApi {
|
|
160
|
+
/**
|
|
161
|
+
* Read one file. Resolves to a string for `'text'`, a parsed value for
|
|
162
|
+
* `'json'`, or a `Uint8Array` for `'bytes'` (see
|
|
163
|
+
* {@link GezelPageReadOptions.as} for the default). Rejects with a
|
|
164
|
+
* {@link GezelPageError} on missing files, out-of-scope paths, or
|
|
165
|
+
* invalid JSON.
|
|
166
|
+
*/
|
|
167
|
+
read(path: string, opts?: GezelPageReadOptions): Promise<unknown>;
|
|
168
|
+
/** List a directory (non-recursive). */
|
|
169
|
+
list(path: string, opts?: GezelPageSourceOptions): Promise<GezelPageDirEntry[]>;
|
|
170
|
+
/**
|
|
171
|
+
* Watch a path and get called back when its content stamp changes.
|
|
172
|
+
* Callbacks carry the new etag only — `read` again for the content.
|
|
173
|
+
*
|
|
174
|
+
* @returns An unsubscribe function; call it to stop the watch.
|
|
175
|
+
*/
|
|
176
|
+
watch(path: string, cb: (ev: GezelPageWatchEvent) => void, opts?: GezelPageWatchOptions): () => void;
|
|
177
|
+
/**
|
|
178
|
+
* A capability-relative URL for the file, for `<img src>` / media
|
|
179
|
+
* elements — the URL embeds the page's read scope, never a credential.
|
|
180
|
+
* Throws a {@link GezelPageError} (`'unavailable'`) when the document
|
|
181
|
+
* URL carries no capability.
|
|
182
|
+
*/
|
|
183
|
+
url(path: string, opts?: GezelPageSourceOptions): string;
|
|
184
|
+
}
|
|
185
|
+
/** The host UI theme as seen by the page. */
|
|
186
|
+
interface GezelPageTheme {
|
|
187
|
+
mode: 'light' | 'dark';
|
|
188
|
+
}
|
|
189
|
+
/** Host UI state the page can mirror. */
|
|
190
|
+
interface GezelPageUiApi {
|
|
191
|
+
/** The current theme. Live — reflects the host's latest pushed value. */
|
|
192
|
+
theme: GezelPageTheme;
|
|
193
|
+
/**
|
|
194
|
+
* Subscribe to theme changes (called only on actual changes).
|
|
195
|
+
*
|
|
196
|
+
* @returns An unsubscribe function.
|
|
197
|
+
*/
|
|
198
|
+
onTheme(cb: (t: GezelPageTheme) => void): () => void;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* The `window.gezel` object a served project-type page codes against.
|
|
202
|
+
* Installed non-writable before any page script runs; absent entirely in
|
|
203
|
+
* demo contexts (see module doc), so feature-detect with `window.gezel`.
|
|
204
|
+
*/
|
|
205
|
+
interface GezelPageApi {
|
|
206
|
+
/** Static facts about this page (identity, params, mode). */
|
|
207
|
+
page: GezelPageInfo;
|
|
208
|
+
/** Invoke the project type's declared tools. */
|
|
209
|
+
tools: GezelPageToolsApi;
|
|
210
|
+
/** Read and watch project files within the page's declared scope. */
|
|
211
|
+
data: GezelPageDataApi;
|
|
212
|
+
/** Mirror host UI state (theme). */
|
|
213
|
+
ui: GezelPageUiApi;
|
|
214
|
+
/** Ask the host to re-serve the page (embedded); reloads the tab in browser mode. */
|
|
215
|
+
refresh(): void;
|
|
216
|
+
}
|
|
217
|
+
declare global {
|
|
218
|
+
interface Window {
|
|
219
|
+
/** Present when the page is served (or stubbed) with the gezel page API. */
|
|
220
|
+
gezel?: GezelPageApi;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export { GEZEL_PAGE_API_VERSION, type GezelPageApi, type GezelPageDataApi, type GezelPageDirEntry, type GezelPageError, type GezelPageErrorCode, type GezelPageInfo, type GezelPageMode, type GezelPageReadOptions, type GezelPageReadSource, type GezelPageSourceOptions, type GezelPageTheme, type GezelPageToolReaction, type GezelPageToolResult, type GezelPageToolsApi, type GezelPageUiApi, type GezelPageWatchEvent, type GezelPageWatchOptions };
|
package/dist/page.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bendyline/gezel-sdk",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "SDK imported by scripts running in the Gezel sandbox. Exposes the `gezel` object and `defineScript` helper.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -48,6 +48,10 @@
|
|
|
48
48
|
"types": "./dist/stores.d.ts",
|
|
49
49
|
"import": "./dist/stores.js"
|
|
50
50
|
},
|
|
51
|
+
"./page": {
|
|
52
|
+
"types": "./dist/page.d.ts",
|
|
53
|
+
"import": "./dist/page.js"
|
|
54
|
+
},
|
|
51
55
|
"./package.json": "./package.json"
|
|
52
56
|
},
|
|
53
57
|
"files": [
|
|
@@ -58,7 +62,7 @@
|
|
|
58
62
|
"tsup": "^8.5.1",
|
|
59
63
|
"typescript": "^6.0.3",
|
|
60
64
|
"vitest": "^4.1.10",
|
|
61
|
-
"@bendyline/gezel": "0.1
|
|
65
|
+
"@bendyline/gezel": "1.0.1"
|
|
62
66
|
},
|
|
63
67
|
"scripts": {
|
|
64
68
|
"build": "tsup",
|