Definitions, state & actions
Define projects, gizmos, validated state, actions and standard controls.
Public exports
Import from @scape-wtf/sdk.
ObjectAction, ObjectActionError, ObjectChoice, ObjectConfiguration, ObjectContext, ObjectControl, ObjectDefinition, ObjectField, ObjectInstance, ObjectListItem, ObjectRowElement, ObjectView, ObjectViewRow, ObjectViewer, PROJECT_OBJECT_LIMIT, ProjectDefinition, ProjectMetadata, actorId, boundedJsonData, defineObject, defineProject, exactKeys, jsonData, localObjectRandomInt, objectId, record, requirePayload, validProjectMetadata.
Type declarations
Import the public exports listed above from the package entry point.
ts
import type { GizmoMarket } from './market.js';
import type { GizmoPendingFeedback, GizmoPendingContext } from './pendingFeedback.js';
import type { ActionButton } from './actionButtons.js';
import type { GizmoWebView } from './web.js';
import type { GizmoMedia } from './media.js';
import type { GizmoConnection, GizmoInput, GizmoOutput, GizmoSignals } from './connections.js';
import type { GizmoNavigation, GizmoWorldEditor } from './navigation.js';
import type { GizmoLink, GizmoTravel, GizmoEnvironment } from './travel.js';
import type { GizmoInteraction, GizmoInteractionFeedback, GizmoReaction, GizmoReactionContext } from './reaction.js';
import type { GizmoSpriteRecipe } from './sprite.js';
import type { GizmoConfiguration } from './configuration.js';
import type { GizmoPreview } from './soundBank.js';
import type { GizmoPush } from './push.js';
import type { GizmoLightingState } from './lighting.js';
import type { GizmoStepEvent, GizmoStepEffects } from './step.js';
import type { GizmoLight } from './light.js';
import type { GizmoSequence } from './sequence.js';
import type { GizmoGlow } from './glow.js';
import type { GizmoAmbience, GizmoSounds, GizmoAudioTimeline } from './audio.js';
import type { GizmoTextEditor } from './text.js';
import type { GizmoPresentation, GizmoTimeline } from './presentation.js';
/** Scape object definition. Scape isolates uploaded code; local SDK tests do not. */
export interface ObjectInstance {
/** Stable identity assigned by Scape for one placed instance. */
id: string;
/** Namespaced definition type that created this instance. */
type: string;
/** Definition version used to validate the saved state. */
version: number;
/** Author-owned state returned by the definition's `initial` and actions. */
state: unknown;
/** Optional Scape-managed link identity for grouped world behavior. */
linkId?: string;
/** Scape-owned outgoing wires; excluded from portable configuration. */
connections?: GizmoConnection[];
/** Last applied held inputs, maintained by Scape, never authored state. */
signalInputs?: Record<string, boolean>;
}
/** Portable editor values only; identities and live state never cross placements. */
export interface ObjectConfiguration {
/** Definition type whose configuration is being stored. */
type: string;
/** Definition version that established the configuration shape. */
version: number;
/** Declared editor values; never include identity, credentials, or live state. */
values: Record<string, unknown>;
}
/** Identity and editing authority visible to a view callback. */
export interface ObjectViewer {
/** Host-issued actor identifier for the viewer. */
actorId: string;
/** Whether the viewer may invoke editor-permission actions. */
canEdit: boolean;
}
/** Authority, clock, and bounded randomness supplied to an authoritative action. */
export interface ObjectContext extends ObjectViewer {
/** Whether this actor may remove the placed instance. */
canRemove?: boolean;
/** Host time in milliseconds; do not use a process clock for game decisions. */
now: number;
/** Host-provided inclusive random integer source. */
randomInt: (min: number, max: number) => number;
}
/** Name and JSON payload submitted to a definition action. */
export interface ObjectAction {
/** Action key declared in the definition. */
name: string;
/** JSON-compatible action input, validated by Scape before execution. */
payload: Record<string, unknown>;
}
/** A participant/editor control rendered by Scape's shared configuration UI. */
export interface ObjectControl {
/** Stable control identifier used by Scape for focus and drafts. */
id: string;
/** Accessible button label and tooltip. */
label: string;
/** Action invoked when the control is submitted. */
action: ObjectAction;
/** Disables submission without changing the action's permission. */
disabled?: boolean;
/** Current state for a toggle control. */
pressed?: boolean;
/** Confirmation message shown before an action. Required for an icon-first button. */
confirm?: string;
/** Two-step content action using a preset or approved icon ID; requires confirm. */
button?: ActionButton;
/** Editor field identifiers submitted with this control. */
fields?: string[];
/** Host action-row switch or tab-open/tab-close toggle; requires boolean pressed state and no fields. */
icon?: 'toggle' | 'tab';
/** Icon-only action row button; defaults to Scape’s media-play-filled icon. Permissions are unchanged. */
placement?: 'action';
/** Save on a committed native change, with no separate button. Text fields require explicit submission. */
trigger?: 'change';
/** A local preview control resolves its action through definition.previews, never the server. */
kind?: 'preview';
/** Audition this named local preview with the same payload before a normal action. */
preview?: string;
}
/** A finite choice is author data; Scape never interprets its value as a game feature. */
export interface ObjectChoice {
/** Stable submitted value. */
value: string;
/** Human-readable label shown in the control. */
label: string;
}
/** A bounded native editor. Dates/times are calendar strings, never implicit timestamps. */
export type ObjectField = {
id: string;
label: string;
value: string;
kind?: 'text';
maxLength: number;
multiline?: boolean;
} | {
id: string;
label: string;
value: string;
kind: 'select';
options: ObjectChoice[];
} | {
id: string;
label: string;
value: string;
kind: 'radio';
options: ObjectChoice[];
} | {
id: string;
label: string;
value: string;
kind: 'date' | 'time';
min?: string;
max?: string;
} | {
id: string;
label: string;
value: string;
kind: 'color';
palette?: string[];
}
/** Host-owned picker restricted to Scape's current scene emoji library. */
| {
id: string;
label: string;
value: string;
kind: 'emoji';
} | {
id: string;
label: string;
value: number;
kind: 'number';
min: number;
max: number;
step: number;
} | {
id: string;
label: string;
value: number;
kind: 'slider';
min: number;
max: number;
step: number;
} | {
id: string;
label: string;
value: boolean;
kind: 'boolean';
} | {
id: string;
label: string;
value: string[];
kind: 'checklist';
options: ObjectChoice[];
};
/** One read-only native list row. All content is plain text. */
export interface ObjectListItem {
id: string;
title: string;
description?: string;
}
/** Reference an existing native element; layout never grants action permission. */
export type ObjectRowElement = {
kind: 'field' | 'control' | 'item';
id: string;
} | {
kind: 'title' | 'description';
};
/** A bounded, responsive row. The host owns spacing, wrapping and field sizes. */
export interface ObjectViewRow {
id: string;
/** Optional accessible group name. */
label?: string;
/** Equal shares by default, or natural content widths. Both wrap when needed. */
sizing?: 'equal' | 'content';
elements: ObjectRowElement[];
}
/** Declarative editor content rendered inside Scape's shared popover. */
export interface ObjectView {
/** Optional rows, in display order. Unreferenced content keeps its normal layout.
* Public and editor-only elements remain in their respective sections.
*/
rows?: ObjectViewRow[];
/** Explicitly public data sent to the definition's opt-in web bridge. Never include credentials. */
webData?: Record<string, unknown>;
/** Accessible equivalent of an embedded web form. Controls bind only to declared web actions. */
webForm?: Pick<ObjectView, 'description' | 'fields' | 'controls'>;
/** Visible panel title. */
title: string;
/** Supporting description for the current state or controls. */
description: string;
/** Up to 32 read-only rows, rendered with native list styling. */
items?: ObjectListItem[];
/** Optional editable fields. */
fields?: ObjectField[];
/** Actions available to the current viewer. */
controls: ObjectControl[];
}
/** Complete author-owned contract for one versioned Scape gizmo type. */
export interface ObjectDefinition {
/** Namespaced, stable identifier for this definition. */
type: string;
/** Increment when saved state or behavior becomes incompatible. */
version: number;
/** Unique emoji identity used by Scape catalog. */
emoji: string;
/** Previous catalog identities accepted for saved instances; omitted from new-placement catalogs. */
legacyEmojis?: string[];
/** Short human-readable name shown in the developer and world UI. */
label: string;
/** Concise hint shown beside the gizmo in catalogs. */
hint: string;
/** Creates fresh state for a placement. Must not read external state. */
initial: () => unknown;
/** Returns true only for valid state for this definition version. */
valid: (state: unknown) => boolean;
/** Authoritative actions keyed by the names used in `ObjectControl.action`. */
actions: Record<string, {
permission: 'participant' | 'editor' | 'remover';
run: (state: unknown, payload: Record<string, unknown>, context: ObjectContext) => unknown;
}>;
inputs?: Record<string, GizmoInput>;
outputs?: Record<string, GizmoOutput>;
signals?: (state: unknown, previous: unknown, action: ObjectAction | null) => GizmoSignals;
interaction?: GizmoInteraction;
/** Immediate local contact audio/bursts, keyed by participant tap/bump action name. */
interactionFeedback?: Record<string, GizmoInteractionFeedback>;
/** Optional local waiting visuals for any action; acceptance/rejection restore confirmed presentation. */
pendingFeedback?: (state: unknown, action: ObjectAction, context: GizmoPendingContext) => GizmoPendingFeedback | null;
areaRemoval?: {
radiusCells: number;
};
react?: (state: unknown, previous: unknown, action: ObjectAction, context: GizmoReactionContext) => GizmoReaction | null;
view?: (state: unknown, viewer: ObjectViewer) => ObjectView;
/** Fixed developer-authored website or bundled HTML. Never derived from saved configuration or view state. */
web?: Omit<GizmoWebView, 'data'>;
/** Host-rendered live media backed by a catalogue, with editor-only shared tuning. */
media?: GizmoMedia;
/** Host-owned market picker and transient quotes; state holds a token or market reference. */
market?: GizmoMarket;
/** Participant editing requires placement and build permission; placer-admin restricts editing to world administrators. Hosts may let administrators edit any creator’s items. */
editPolicy?: 'placer' | 'placer-admin';
textEditor?: GizmoTextEditor;
worldEditor?: GizmoWorldEditor;
/** Optional proximity limit for the world label, in cells. */
worldTextRange?: number;
navigate?: (state: unknown) => GizmoNavigation | null;
configuration?: GizmoConfiguration;
worldText?: (state: unknown) => string;
presentation?: GizmoPresentation;
sprite?: (state: unknown) => GizmoSpriteRecipe;
sounds?: GizmoSounds;
/** Alternative to static sounds: up to 16 pitch/state-specific recipes, at most 64 KiB. */
soundBank?: (state: unknown) => GizmoSounds;
previews?: Record<string, {
permission: 'participant' | 'editor';
run: (state: unknown, payload: Record<string, unknown>) => GizmoPreview;
}>;
audio?: (state: unknown, previous: unknown) => GizmoAudioTimeline | null;
ambience?: GizmoAmbience;
sequence?: GizmoSequence;
glow?: GizmoGlow;
light?: GizmoLight;
/** Replaces fixed light/glow for this state; absent effects are off. */
lighting?: (state: unknown, environment: GizmoEnvironment) => GizmoLightingState;
/** Explicit collision policy. Defaults to false; fixed for this definition version. */
walkable?: boolean;
/** Host-assigned grouping, independent of movement. */
link?: GizmoLink;
travel?: (state: unknown) => GizmoTravel | null;
/** Decorative rotation in radians/second; disabled for reduced motion. */
spin?: number;
/** State-derived directional push while occupied. Requires walkable: true; Scape handles movement. */
push?: (state: unknown) => GizmoPush | null;
/** Cosmetic arrival feedback only. Does not grant walkability or change saved state. */
step?: (state: unknown, event: GizmoStepEvent) => GizmoStepEffects | null;
animate?: (state: unknown, previous: unknown) => GizmoTimeline;
}
export declare class ObjectActionError extends Error {
readonly status: 400 | 403 | 409;
constructor(status: 400 | 403 | 409, message: string);
}
export declare const record: (value: unknown) => value is Record<string, unknown>;
export declare const exactKeys: (value: Record<string, unknown>, keys: string[]) => boolean;
export declare const actorId: (value: unknown) => value is string;
export declare const objectId: (value: unknown) => value is string;
/** Typed authoring helper; the registry checks state before invoking an implementation. */
export declare function defineObject<S>(definition: Omit<ObjectDefinition, 'signals' | 'initial' | 'valid' | 'actions' | 'view' | 'animate' | 'worldText' | 'audio' | 'lighting' | 'step' | 'push' | 'soundBank' | 'previews' | 'sprite' | 'react' | 'pendingFeedback' | 'travel' | 'navigate'> & {
signals?: (state: S, previous: S, action: ObjectAction | null) => GizmoSignals;
initial: () => S;
valid: (state: unknown) => state is S;
actions: Record<string, {
permission: 'participant' | 'editor' | 'remover';
run: (state: S, payload: Record<string, unknown>, context: ObjectContext) => S;
}>;
pendingFeedback?: (state: S, action: ObjectAction, context: GizmoPendingContext) => GizmoPendingFeedback | null;
react?: (state: S, previous: S, action: ObjectAction, context: GizmoReactionContext) => GizmoReaction | null;
view?: (state: S, viewer: ObjectViewer) => ObjectView;
soundBank?: (state: S) => GizmoSounds;
sprite?: (state: S) => GizmoSpriteRecipe;
previews?: Record<string, {
permission: 'participant' | 'editor';
run: (state: S, payload: Record<string, unknown>) => GizmoPreview;
}>;
worldText?: (state: S) => string;
navigate?: (state: S) => GizmoNavigation | null;
travel?: (state: S) => GizmoTravel | null;
lighting?: (state: S, environment: GizmoEnvironment) => GizmoLightingState;
push?: (state: S) => GizmoPush | null;
step?: (state: S, event: GizmoStepEvent) => GizmoStepEffects | null;
animate?: (state: S, previous: S) => GizmoTimeline;
audio?: (state: S, previous: S) => GizmoAudioTimeline | null;
}): ObjectDefinition;
export declare function requirePayload(payload: Record<string, unknown>, keys: string[]): void;
/** Validate untrusted structured-clone input without expanding shared graphs.
* Work is bounded by the encoded-character budget, not just nesting depth.
* Repeated object references and cycles are rejected before serialization.
*/
export declare function boundedJsonData(value: unknown, maxLength: number): boolean;
/** Persistent state and action payloads must round-trip through JSON without loss. */
export declare function jsonData(value: unknown, depth?: number): boolean;
/** Local simulation randomness; connected actions always use the server context. */
export declare function localObjectRandomInt(min: number, max: number): number;
/** One atomic development build. Object state remains independent per placed instance. */
export interface ProjectDefinition {
/** Public product title. */
name: string;
/** Public product description, captured with each release. Required for shop submission. */
description: string;
objects: readonly ObjectDefinition[];
}
export interface ProjectMetadata {
name: string;
description: string;
}
/** Project copy uses the same bounds in the authoring SDK, sandbox and shop. */
export declare function validProjectMetadata(value: unknown): value is ProjectMetadata;
export declare const PROJECT_OBJECT_LIMIT = 16;
export declare function defineProject(project: ProjectDefinition): ProjectDefinition;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
Usage and limits
See Gizmo guides, working examples, and limits for lifecycle, validation and Scape behavior.
