@rool-dev/client 0.3.1 → 0.4.0-dev.5967e76

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.
@@ -0,0 +1,255 @@
1
+ import { EventEmitter } from './event-emitter.js';
2
+ import type { GraphQLClient } from './graphql.js';
3
+ import type { MediaClient } from './media.js';
4
+ import type { RoolSpaceData, RoolObject, JSONPatchOp, SpaceEvents, RoolUserRole, RoolUser, PromptOptions, MediaItem } from './types.js';
5
+ export declare function generateEntityId(): string;
6
+ interface SpaceConfig {
7
+ id: string;
8
+ name: string;
9
+ role: RoolUserRole;
10
+ initialData: RoolSpaceData;
11
+ graphqlClient: GraphQLClient;
12
+ mediaClient: MediaClient;
13
+ onRegisterForEvents: (spaceId: string, space: RoolSpace) => void;
14
+ onUnregisterFromEvents: (spaceId: string) => void;
15
+ }
16
+ /**
17
+ * First-class Space object.
18
+ *
19
+ * Features:
20
+ * - High-level object/link operations
21
+ * - Built-in undo/redo with checkpoints
22
+ * - Metadata management
23
+ * - Event emission for state changes
24
+ * - Real-time subscription support
25
+ */
26
+ export declare class RoolSpace extends EventEmitter<SpaceEvents> {
27
+ private _id;
28
+ private _name;
29
+ private _role;
30
+ private _data;
31
+ private graphqlClient;
32
+ private mediaClient;
33
+ private onRegisterForEvents;
34
+ private onUnregisterFromEvents;
35
+ private undoStack;
36
+ private redoStack;
37
+ private _isSubscribed;
38
+ constructor(config: SpaceConfig);
39
+ get id(): string;
40
+ get name(): string;
41
+ get role(): RoolUserRole;
42
+ get isReadOnly(): boolean;
43
+ get isSubscribed(): boolean;
44
+ /**
45
+ * Rename this space.
46
+ */
47
+ rename(newName: string): Promise<void>;
48
+ /**
49
+ * Subscribe to real-time updates for this space.
50
+ * Registers with the client for event routing.
51
+ */
52
+ subscribe(): void;
53
+ /**
54
+ * Unsubscribe from real-time updates.
55
+ */
56
+ unsubscribe(): void;
57
+ /**
58
+ * Close this space and clean up resources.
59
+ */
60
+ close(): void;
61
+ /**
62
+ * Create a checkpoint for undo.
63
+ * Call this before a user action to capture the current state.
64
+ */
65
+ checkpoint(label?: string): void;
66
+ /**
67
+ * Check if undo is available.
68
+ */
69
+ canUndo(): boolean;
70
+ /**
71
+ * Check if redo is available.
72
+ */
73
+ canRedo(): boolean;
74
+ /**
75
+ * Undo to the previous checkpoint.
76
+ * @returns true if undo was performed
77
+ */
78
+ undo(): Promise<boolean>;
79
+ /**
80
+ * Redo a previously undone action.
81
+ * @returns true if redo was performed
82
+ */
83
+ redo(): Promise<boolean>;
84
+ /**
85
+ * Clear undo/redo history.
86
+ * Called when external changes invalidate local history.
87
+ */
88
+ clearHistory(): void;
89
+ /**
90
+ * Get an object's data by ID.
91
+ * Returns just the data portion (RoolObject), not the full entry with meta/links.
92
+ * @throws Error if object not found
93
+ */
94
+ getObject(objectId: string): RoolObject;
95
+ /**
96
+ * Get an object's data by ID, or undefined if not found.
97
+ */
98
+ getObjectOrUndefined(objectId: string): RoolObject | undefined;
99
+ /**
100
+ * Get an object's metadata (position, UI state, etc).
101
+ */
102
+ getObjectMeta(objectId: string): Record<string, unknown>;
103
+ /**
104
+ * Get all objects of a specific type.
105
+ */
106
+ getObjectsByType(type: string): RoolObject[];
107
+ /**
108
+ * Get all object IDs.
109
+ */
110
+ getObjectIds(): string[];
111
+ /**
112
+ * Create a new object with optional AI generation.
113
+ * @param options.type - The object type (required)
114
+ * @param options.fields - Object fields (optional). Use {{placeholder}} for AI-generated content.
115
+ * @param options.meta - Client-private metadata (optional). Hidden from AI operations.
116
+ * @param options.prompt - AI prompt for content generation (optional).
117
+ * @returns The generated object ID
118
+ */
119
+ createObject(options: {
120
+ type: string;
121
+ fields?: Record<string, unknown>;
122
+ meta?: Record<string, unknown>;
123
+ prompt?: string;
124
+ }): Promise<{
125
+ id: string;
126
+ message: string;
127
+ }>;
128
+ /**
129
+ * Update an existing object.
130
+ * @param objectId - The ID of the object to update
131
+ * @param options.type - Optional new type for the object
132
+ * @param options.fields - Fields to add or update. Use {{placeholder}} for AI-generated content.
133
+ * @param options.meta - Client-private metadata to merge. Hidden from AI operations.
134
+ * @param options.prompt - AI prompt for content editing (optional).
135
+ */
136
+ updateObject(objectId: string, options: {
137
+ type?: string;
138
+ fields?: Record<string, unknown>;
139
+ meta?: Record<string, unknown>;
140
+ prompt?: string;
141
+ }): Promise<string>;
142
+ /**
143
+ * Delete objects by IDs.
144
+ * Outbound links are automatically deleted with the object.
145
+ * Inbound links become orphans (tolerated).
146
+ */
147
+ deleteObjects(objectIds: string[]): Promise<void>;
148
+ /**
149
+ * Create a link between objects.
150
+ * Links are stored on the source object.
151
+ */
152
+ link(sourceId: string, targetId: string, linkType: string): Promise<void>;
153
+ /**
154
+ * Remove a link between two objects.
155
+ * @param linkType - Optional: if provided, only removes that type; otherwise removes all links between the objects
156
+ * @returns true if any links were removed
157
+ */
158
+ unlink(sourceId: string, targetId: string, linkType?: string): Promise<boolean>;
159
+ /**
160
+ * Get parent object IDs (objects that have links pointing TO this object).
161
+ * @param linkType - Optional filter by link type
162
+ */
163
+ getParents(objectId: string, linkType?: string): string[];
164
+ /**
165
+ * Get child object IDs (objects that this object has links pointing TO).
166
+ * Filters out orphan targets (targets that don't exist).
167
+ * @param linkType - Optional filter by link type
168
+ */
169
+ getChildren(objectId: string, linkType?: string): string[];
170
+ /**
171
+ * Get all child object IDs including orphans (targets that may not exist).
172
+ * @param linkType - Optional filter by link type
173
+ */
174
+ getChildrenIncludingOrphans(objectId: string, linkType?: string): string[];
175
+ /**
176
+ * Set a space-level metadata value.
177
+ * Metadata is stored in meta and hidden from AI operations.
178
+ */
179
+ setMetadata(key: string, value: unknown): void;
180
+ /**
181
+ * Get a space-level metadata value.
182
+ */
183
+ getMetadata(key: string): unknown;
184
+ /**
185
+ * Get all space-level metadata.
186
+ */
187
+ getAllMetadata(): Record<string, unknown>;
188
+ /**
189
+ * Send a prompt to the AI agent for space manipulation.
190
+ */
191
+ prompt(prompt: string, options?: PromptOptions): Promise<string | null>;
192
+ /**
193
+ * List users with access to this space.
194
+ */
195
+ listUsers(): Promise<RoolUser[]>;
196
+ /**
197
+ * Add a user to this space with specified role.
198
+ */
199
+ addUser(userId: string, role: RoolUserRole): Promise<void>;
200
+ /**
201
+ * Remove a user from this space.
202
+ */
203
+ removeUser(userId: string): Promise<void>;
204
+ /**
205
+ * List all media files for this space.
206
+ */
207
+ listMedia(): Promise<MediaItem[]>;
208
+ /**
209
+ * Upload a file to this space.
210
+ */
211
+ uploadMedia(file: File | Blob | {
212
+ data: string;
213
+ contentType: string;
214
+ }): Promise<MediaItem>;
215
+ /**
216
+ * Get the URL for a media file.
217
+ */
218
+ getMediaUrl(uuid: string): string;
219
+ /**
220
+ * Download a media file as a Blob.
221
+ */
222
+ downloadMedia(uuid: string): Promise<Blob>;
223
+ /**
224
+ * Delete a media file.
225
+ */
226
+ deleteMedia(uuid: string): Promise<void>;
227
+ /**
228
+ * Get the full space data.
229
+ * Use sparingly - prefer specific operations.
230
+ */
231
+ getData(): RoolSpaceData;
232
+ /**
233
+ * Handle a patch event from another client.
234
+ * @internal
235
+ */
236
+ handleRemotePatch(patch: JSONPatchOp[], source?: 'user' | 'agent'): void;
237
+ /**
238
+ * Parse JSON patch operations and emit semantic events.
239
+ * @internal
240
+ */
241
+ private emitSemanticEventsFromPatch;
242
+ /**
243
+ * Handle a full reload from server.
244
+ * @internal
245
+ */
246
+ handleRemoteChange(newData: RoolSpaceData): void;
247
+ /**
248
+ * Update the name from external source.
249
+ * @internal
250
+ */
251
+ handleRemoteRename(newName: string): void;
252
+ private resyncFromServer;
253
+ }
254
+ export {};
255
+ //# sourceMappingURL=space.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"space.d.ts","sourceRoot":"","sources":["../src/space.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW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