@rool-dev/svelte 0.1.4 → 0.1.6-dev.fdaf8f8

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/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Rool Svelte
2
2
 
3
- Svelte 5 bindings for Rool Spaces. Transforms the event-based SDK into reactive state using `$state` runes.
3
+ Svelte 5 bindings for Rool Spaces. Adds reactive state to the SDK using `$state` runes.
4
4
 
5
- **Requires Svelte 5.** For core concepts (objects, relations, AI placeholders, undo/redo), see the [SDK documentation](https://docs.rool.dev/sdk/).
5
+ **Requires Svelte 5.** For core concepts (objects, relations, AI placeholders, undo/redo), see the [SDK documentation](../sdk/README.md).
6
6
 
7
7
  ## Installation
8
8
 
@@ -18,6 +18,8 @@ npm install @rool-dev/svelte
18
18
 
19
19
  const rool = createRool();
20
20
  rool.init();
21
+
22
+ let currentSpace = $state(null);
21
23
  </script>
22
24
 
23
25
  {#if !rool.authenticated}
@@ -25,13 +27,32 @@ npm install @rool-dev/svelte
25
27
  {:else}
26
28
  <h1>My Spaces</h1>
27
29
  {#each rool.spaces ?? [] as space}
28
- <button onclick={() => rool.openSpace(space.id)}>
30
+ <button onclick={async () => currentSpace = await rool.openSpace(space.id)}>
29
31
  {space.name}
30
32
  </button>
31
33
  {/each}
34
+
35
+ {#if currentSpace}
36
+ <p>Interactions: {currentSpace.interactions.length}</p>
37
+ {/if}
32
38
  {/if}
33
39
  ```
34
40
 
41
+ ## What It Provides
42
+
43
+ The Svelte wrapper adds reactive state on top of the SDK:
44
+
45
+ | Reactive Property | Description |
46
+ |-------------------|-------------|
47
+ | `rool.authenticated` | Auth state (`null` = checking, `true`/`false` = known) |
48
+ | `rool.spaces` | List of available spaces |
49
+ | `rool.spacesLoading` | Whether spaces are loading |
50
+ | `rool.spacesError` | Error from loading spaces |
51
+ | `rool.connectionState` | SSE connection state |
52
+ | `space.interactions` | Conversation interactions (auto-updates) |
53
+
54
+ Everything else passes through to the SDK directly. See the [SDK documentation](../sdk/README.md) for full API details.
55
+
35
56
  ## API
36
57
 
37
58
  ### Lifecycle
@@ -41,16 +62,16 @@ const rool = createRool();
41
62
 
42
63
  rool.init(); // Process auth callbacks (call on app startup)
43
64
  rool.login('My App'); // Redirect to login page
44
- rool.logout(); // Clear auth state
65
+ rool.logout(); // Clear auth state and close all spaces
45
66
  rool.destroy(); // Clean up all resources
46
67
  ```
47
68
 
48
- ### Client State (Always Available)
69
+ ### Client State
49
70
 
50
71
  ```svelte
51
72
  <script>
52
- // Direct property access - automatically reactive
53
- // rool.authenticated → boolean
73
+ // All properties are reactive $state
74
+ // rool.authenticated → boolean | null
54
75
  // rool.spaces → RoolSpaceInfo[] | undefined
55
76
  // rool.spacesLoading → boolean
56
77
  // rool.spacesError → Error | null
@@ -68,9 +89,7 @@ rool.destroy(); // Clean up all resources
68
89
  {/if}
69
90
  ```
70
91
 
71
- ### Space Lifecycle
72
-
73
- Opening a space returns a `SpaceHandle` with reactive state and methods:
92
+ ### Opening Spaces
74
93
 
75
94
  ```typescript
76
95
  const space = await rool.openSpace('space-id');
@@ -85,171 +104,90 @@ const spaceB = await rool.openSpace('space-b');
85
104
  space.close();
86
105
  ```
87
106
 
88
- ### Space State
89
-
90
- ```svelte
91
- <script>
92
- // space.info → { id, name, role }
93
- // space.conversationId → string
94
- // space.conversations → ConversationInfo[] | undefined
95
- // space.conversationsLoading → boolean
96
- // space.interactions → Interaction[]
97
- // space.systemInstruction → string | undefined
98
- </script>
99
-
100
- <h1>{space.info.name}</h1>
101
- <p>Role: {space.info.role}</p>
102
-
103
- <!-- Conversation picker -->
104
- <select onchange={(e) => space.setConversationId(e.target.value)}>
105
- {#each space.conversations ?? [] as conv}
106
- <option value={conv.id} selected={conv.id === space.conversationId}>
107
- {conv.name ?? 'Untitled'}
108
- </option>
109
- {/each}
110
- </select>
111
-
112
- <!-- Chat messages -->
113
- {#each space.interactions as interaction}
114
- <div class="message">
115
- <strong>{interaction.operation}</strong>
116
- <p>{interaction.output}</p>
117
- </div>
118
- {/each}
119
- ```
120
-
121
- ### Object Factories
107
+ ### ReactiveSpace
122
108
 
123
- Object state is created via factory functions and cached by arguments. Each returns an `AsyncValue` with reactive `value`, `loading`, and `error` properties.
109
+ `openSpace` and `createSpace` return a `ReactiveSpace` the SDK's `RoolSpace` with reactive `interactions`:
124
110
 
125
111
  ```svelte
126
112
  <script>
127
- // Single object
128
- const sun = space.object('sun-id');
129
- // sun.value → RoolObject | undefined
130
- // sun.loading → boolean
131
- // sun.error → Error | null
132
-
133
- // Children (objects this object links TO)
134
- const planets = space.children('sun-id', 'hasPlanet');
135
-
136
- // Parents (objects that link TO this object)
137
- const stars = space.parents('earth-id', 'orbits');
113
+ let space = $state(null);
138
114
 
139
- // Query (manual refresh only)
140
- const articles = space.query({ where: { type: 'article' } });
115
+ async function open(id) {
116
+ space = await rool.openSpace(id);
117
+ }
141
118
  </script>
142
119
 
143
- {#if sun.loading}
144
- <p>Loading...</p>
145
- {:else if sun.error}
146
- <p>Error: {sun.error.message}</p>
147
- {:else if sun.value}
148
- <h1>{sun.value.name}</h1>
149
- {/if}
120
+ {#if space}
121
+ <!-- Reactive: updates as AI makes tool calls -->
122
+ {#each space.interactions as interaction}
123
+ <div>
124
+ <strong>{interaction.operation}</strong>: {interaction.output}
125
+ </div>
126
+ {/each}
150
127
 
151
- <!-- Manual refresh -->
152
- <button onclick={() => articles.refresh()}>Refresh</button>
128
+ <!-- All SDK methods work directly -->
129
+ <button onclick={() => space.prompt('Hello')}>Send</button>
130
+ {/if}
153
131
  ```
154
132
 
155
- ### Mutations
133
+ ### Using the SDK
156
134
 
157
- All mutations are async and pass through to the underlying SDK.
135
+ All `RoolSpace` methods and properties are available on `ReactiveSpace`:
158
136
 
159
137
  ```typescript
160
- // Create objects
161
- const { object, message } = await space.createObject({
162
- data: { type: 'article', title: 'Hello World' }
163
- });
164
-
165
- // Update objects
166
- await space.updateObject(object.id, {
167
- data: { status: 'published' }
168
- });
169
-
170
- // Delete objects
171
- await space.deleteObjects([object.id]);
172
-
173
- // Links
174
- await space.link(sourceId, 'references', targetId);
175
- await space.unlink(sourceId, 'references', targetId);
176
-
177
- // AI prompt
178
- const { message, objects } = await space.prompt(
179
- 'Create a summary of all articles'
180
- );
138
+ // Properties
139
+ space.id
140
+ space.name
141
+ space.role
142
+ space.conversationId
143
+
144
+ // Object operations
145
+ await space.getObject(id)
146
+ await space.createObject({ data: { type: 'note', text: 'Hello' } })
147
+ await space.updateObject(id, { data: { text: 'Updated' } })
148
+ await space.deleteObjects([id])
149
+ await space.findObjects({ where: { type: 'note' } })
150
+
151
+ // Relations
152
+ await space.link(sourceId, 'references', targetId)
153
+ await space.unlink(sourceId, 'references', targetId)
154
+ await space.getChildren(id, 'references')
155
+ await space.getParents(id, 'references')
156
+
157
+ // AI
158
+ await space.prompt('Summarize everything')
181
159
 
182
160
  // Undo/Redo
183
- await space.checkpoint('Before edit');
184
- await space.updateObject(id, { data: { title: 'New title' } });
185
- await space.undo(); // Reverts the update
186
- await space.redo(); // Reapplies the update
161
+ await space.checkpoint('Before edit')
162
+ await space.undo()
163
+ await space.redo()
164
+
165
+ // Conversations
166
+ await space.setSystemInstruction('You are helpful')
167
+ await space.renameConversation('id', 'Research')
168
+ space.getInteractions()
187
169
  ```
188
170
 
189
- ### Conversation Management
190
-
191
- ```typescript
192
- space.setConversationId('new-convo-id');
193
- await space.setSystemInstruction('You are a helpful assistant');
194
- await space.renameConversation('convo-id', 'Research Thread');
195
- await space.deleteConversation('convo-id');
196
- ```
171
+ See the [SDK documentation](../sdk/README.md) for complete API details.
197
172
 
198
173
  ### Utilities
199
174
 
200
175
  ```typescript
201
176
  import { generateId } from '@rool-dev/svelte';
202
177
 
203
- // Generate a 6-character alphanumeric ID (same as RoolClient.generateId())
178
+ // Generate a 6-character alphanumeric ID
204
179
  const id = generateId();
205
180
  ```
206
181
 
207
- ## Auto-Refresh Behavior
208
-
209
- | State | Auto-refreshes on |
210
- |-------|-------------------|
211
- | `object(id)` | `objectUpdated`/`objectDeleted` for that ID |
212
- | `children(id, rel)` | `linked`/`unlinked` events + member object updates |
213
- | `parents(id, rel)` | `linked`/`unlinked` events + member object updates |
214
- | `query(options)` | Never (call `refresh()` manually) |
215
- | `rool.spaces` | `spaceCreated`/`spaceDeleted`/`spaceRenamed` |
216
- | `space.conversations` | `conversationsChanged` |
217
- | `space.interactions` | `conversationUpdated` + `conversationIdChanged` |
218
-
219
- ## AsyncValue Interface
220
-
221
- Object factories return `AsyncValue` instances:
222
-
223
- ```typescript
224
- class AsyncValue<T> {
225
- value: T | undefined; // The data (reactive)
226
- loading: boolean; // Loading state (reactive)
227
- error: Error | null; // Last error (reactive)
228
- refresh(): Promise<void>; // Manually refresh
229
- }
230
- ```
231
-
232
- ## Design Principles
233
-
234
- 1. **Svelte 5 runes** — Uses `$state` for reactivity, no legacy stores
235
- 2. **Direct property access** — No `$` prefix needed, just access properties
236
- 3. **Go through the API** — Never exposes raw space data, all access via SDK methods
237
- 4. **Auto-refresh where safe** — Object/relation state auto-refreshes; queries are manual
238
- 5. **Caching** — Factory functions return cached instances by arguments
239
-
240
182
  ## Exported Types
241
183
 
242
184
  ```typescript
243
185
  // Package types
244
- import type {
245
- Rool,
246
- SpaceHandle,
247
- SpaceInfo,
248
- AsyncValue,
249
- } from '@rool-dev/svelte';
186
+ import type { Rool, ReactiveSpace } from '@rool-dev/svelte';
250
187
 
251
188
  // Re-exported from @rool-dev/sdk
252
189
  import type {
190
+ RoolSpace,
253
191
  RoolSpaceInfo,
254
192
  RoolObject,
255
193
  RoolUserRole,
@@ -265,7 +203,8 @@ import type {
265
203
 
266
204
  ## Examples
267
205
 
268
- See the [svelte-chat example](https://github.com/rool-dev/rool-js/tree/main/examples/svelte-chat) for a complete working app.
206
+ - [soft-sql](../../examples/soft-sql) SQL-style natural language queries with live tool call progress
207
+ - [flashcards](../../examples/flashcards) — Spaced repetition with AI-generated cards
269
208
 
270
209
  ## License
271
210
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  export { createRool, generateId } from './rool.svelte.js';
2
- export type { Rool, SpaceHandle, SpaceInfo, AsyncValue, CreateObjectOptions, UpdateObjectOptions, RoolSpaceInfo, RoolObject, RoolUserRole, ConnectionState, ConversationInfo, Interaction, FindObjectsOptions, PromptOptions, } from './types.js';
2
+ export { wrapSpace } from './space.svelte.js';
3
+ export type { Rool } from './rool.svelte.js';
4
+ export type { ReactiveSpace } from './space.svelte.js';
5
+ export type { RoolSpace, RoolSpaceInfo, RoolObject, RoolUserRole, ConnectionState, ConversationInfo, Interaction, FindObjectsOptions, PromptOptions, CreateObjectOptions, UpdateObjectOptions, } from '@rool-dev/sdk';
3
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG1D,YAAY,EAEV,IAAI,EACJ,WAAW,EACX,SAAS,EACT,UAAU,EACV,mBAAmB,EACnB,mBAAmB,EAEnB,aAAa,EACb,UAAU,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,aAAa,GACd,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG1D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C,YAAY,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD,YAAY,EACV,SAAS,EACT,aAAa,EACb,UAAU,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,4 @@
1
1
  // Main export
2
2
  export { createRool, generateId } from './rool.svelte.js';
3
+ // Reactive space wrapper
4
+ export { wrapSpace } from './space.svelte.js';
@@ -1,7 +1,12 @@
1
1
  import { type RoolSpaceInfo, type ConnectionState } from '@rool-dev/sdk';
2
- import { type SpaceHandle } from './space.svelte.js';
2
+ import { type ReactiveSpace } from './space.svelte.js';
3
3
  /**
4
- * Rool client with reactive state using Svelte 5 runes.
4
+ * Rool client with reactive state for Svelte 5.
5
+ *
6
+ * Provides:
7
+ * - Reactive auth state (`authenticated`)
8
+ * - Reactive spaces list (`spaces`)
9
+ * - Direct access to SDK spaces (no wrapper abstraction)
5
10
  */
6
11
  declare class RoolImpl {
7
12
  #private;
@@ -11,22 +16,44 @@ declare class RoolImpl {
11
16
  spacesError: Error | null;
12
17
  connectionState: ConnectionState;
13
18
  constructor();
19
+ /**
20
+ * Initialize the client. Call on app startup.
21
+ * Returns true if authenticated, false otherwise.
22
+ */
14
23
  init(): Promise<boolean>;
24
+ /**
25
+ * Redirect to login page.
26
+ */
15
27
  login(appName: string): void;
28
+ /**
29
+ * Log out and close all open spaces.
30
+ */
16
31
  logout(): void;
32
+ /**
33
+ * Open an existing space. Returns a ReactiveSpace with reactive `interactions`.
34
+ */
17
35
  openSpace(id: string, options?: {
18
36
  conversationId?: string;
19
- }): Promise<SpaceHandle>;
37
+ }): Promise<ReactiveSpace>;
38
+ /**
39
+ * Create a new space. Returns a ReactiveSpace with reactive `interactions`.
40
+ */
20
41
  createSpace(name?: string, options?: {
21
42
  conversationId?: string;
22
- }): Promise<SpaceHandle>;
43
+ }): Promise<ReactiveSpace>;
44
+ /**
45
+ * Manually refresh the spaces list.
46
+ */
23
47
  refreshSpaces(): Promise<void>;
48
+ /**
49
+ * Clean up resources.
50
+ */
24
51
  destroy(): void;
25
52
  }
26
53
  /**
27
54
  * Create a new Rool instance.
28
55
  */
29
- export declare function createRool(): RoolImpl;
56
+ export declare function createRool(): Rool;
30
57
  /**
31
58
  * Generate a unique 6-character alphanumeric ID.
32
59
  */
@@ -1 +1 @@
1
- {"version":3,"file":"rool.svelte.d.ts","sourceRoot":"","sources":["../src/rool.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAExE;;GAEG;AACH,cAAM,QAAQ;;IAOZ,aAAa,iBAAgC;IAC7C,MAAM,8BAAkD;IACxD,aAAa,UAAiB;IAC9B,WAAW,eAA8B;IACzC,eAAe,kBAA2C;;IAsDpD,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAQ9B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI5B,MAAM,IAAI,IAAI;IAYR,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAelF,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAmB7F,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ9B,OAAO,IAAI,IAAI;CAahB;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,QAAQ,CAErC;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,MAAM,MAAM,IAAI,GAAG,QAAQ,CAAC"}
1
+ {"version":3,"file":"rool.svelte.d.ts","sourceRoot":"","sources":["../src/rool.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElE;;;;;;;GAOG;AACH,cAAM,QAAQ;;IAMZ,aAAa,iBAAgC;IAC7C,MAAM,8BAAkD;IACxD,aAAa,UAAiB;IAC9B,WAAW,eAA8B;IACzC,eAAe,kBAA2C;;IAkD1D;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAQ9B;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI5B;;OAEG;IACH,MAAM,IAAI,IAAI;IAQd;;OAEG;IACG,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAO1F;;OAEG;IACG,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAO/F;;OAEG;IACH,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B;;OAEG;IACH,OAAO,IAAI,IAAI;CAahB;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAEjC;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,MAAM,MAAM,IAAI,GAAG,QAAQ,CAAC"}
@@ -1,15 +1,19 @@
1
1
  import { RoolClient } from '@rool-dev/sdk';
2
- import { createSpaceHandle } from './space.svelte.js';
2
+ import { wrapSpace } from './space.svelte.js';
3
3
  /**
4
- * Rool client with reactive state using Svelte 5 runes.
4
+ * Rool client with reactive state for Svelte 5.
5
+ *
6
+ * Provides:
7
+ * - Reactive auth state (`authenticated`)
8
+ * - Reactive spaces list (`spaces`)
9
+ * - Direct access to SDK spaces (no wrapper abstraction)
5
10
  */
6
11
  class RoolImpl {
7
12
  #client;
8
13
  #unsubscribers = [];
9
14
  #openSpaces = new Set();
10
15
  // Reactive state
11
- // null = unknown (checking), false = not authenticated, true = authenticated
12
- authenticated = $state(null);
16
+ authenticated = $state(null); // null = checking, false = not auth, true = auth
13
17
  spaces = $state(undefined);
14
18
  spacesLoading = $state(false);
15
19
  spacesError = $state(null);
@@ -58,9 +62,10 @@ class RoolImpl {
58
62
  this.spacesLoading = false;
59
63
  }
60
64
  }
61
- // ===========================================================================
62
- // Lifecycle
63
- // ===========================================================================
65
+ /**
66
+ * Initialize the client. Call on app startup.
67
+ * Returns true if authenticated, false otherwise.
68
+ */
64
69
  async init() {
65
70
  this.authenticated = await this.#client.initialize();
66
71
  if (this.authenticated) {
@@ -68,9 +73,15 @@ class RoolImpl {
68
73
  }
69
74
  return this.authenticated;
70
75
  }
76
+ /**
77
+ * Redirect to login page.
78
+ */
71
79
  login(appName) {
72
80
  this.#client.login(appName);
73
81
  }
82
+ /**
83
+ * Log out and close all open spaces.
84
+ */
74
85
  logout() {
75
86
  for (const space of this.#openSpaces) {
76
87
  space.close();
@@ -78,42 +89,33 @@ class RoolImpl {
78
89
  this.#openSpaces.clear();
79
90
  this.#client.logout();
80
91
  }
81
- // ===========================================================================
82
- // Space Lifecycle
83
- // ===========================================================================
92
+ /**
93
+ * Open an existing space. Returns a ReactiveSpace with reactive `interactions`.
94
+ */
84
95
  async openSpace(id, options) {
85
- const sdkSpace = await this.#client.openSpace(id, options);
86
- const handle = createSpaceHandle(sdkSpace);
87
- this.#openSpaces.add(handle);
88
- // Track when closed
89
- const originalClose = handle.close.bind(handle);
90
- handle.close = () => {
91
- this.#openSpaces.delete(handle);
92
- originalClose();
93
- };
94
- return handle;
96
+ const space = await this.#client.openSpace(id, options);
97
+ const reactiveSpace = wrapSpace(space);
98
+ this.#openSpaces.add(reactiveSpace);
99
+ return reactiveSpace;
95
100
  }
101
+ /**
102
+ * Create a new space. Returns a ReactiveSpace with reactive `interactions`.
103
+ */
96
104
  async createSpace(name, options) {
97
- const sdkSpace = await this.#client.createSpace(name, options);
98
- const handle = createSpaceHandle(sdkSpace);
99
- this.#openSpaces.add(handle);
100
- // Track when closed
101
- const originalClose = handle.close.bind(handle);
102
- handle.close = () => {
103
- this.#openSpaces.delete(handle);
104
- originalClose();
105
- };
106
- return handle;
105
+ const space = await this.#client.createSpace(name, options);
106
+ const reactiveSpace = wrapSpace(space);
107
+ this.#openSpaces.add(reactiveSpace);
108
+ return reactiveSpace;
107
109
  }
108
- // ===========================================================================
109
- // Spaces management
110
- // ===========================================================================
110
+ /**
111
+ * Manually refresh the spaces list.
112
+ */
111
113
  refreshSpaces() {
112
114
  return this.#refreshSpaces();
113
115
  }
114
- // ===========================================================================
115
- // Cleanup
116
- // ===========================================================================
116
+ /**
117
+ * Clean up resources.
118
+ */
117
119
  destroy() {
118
120
  for (const space of this.#openSpaces) {
119
121
  space.close();
@@ -1,62 +1,75 @@
1
- import type { RoolSpace, RoolObject, ConversationInfo, Interaction, FindObjectsOptions, PromptOptions, CreateObjectOptions, UpdateObjectOptions, RoolUserRole } from '@rool-dev/sdk';
2
- export interface SpaceInfo {
3
- id: string;
4
- name: string;
5
- role: RoolUserRole;
6
- }
7
- export declare class AsyncValue<T> {
8
- #private;
9
- value: T | undefined;
10
- loading: boolean;
11
- error: Error | null;
12
- constructor(fetcher: () => Promise<T>, fetchOnCreate?: boolean);
13
- refresh(): Promise<void>;
14
- set(value: T | undefined): void;
15
- clear(): void;
16
- }
17
- declare class SpaceHandleImpl {
1
+ import type { RoolSpace, Interaction } from '@rool-dev/sdk';
2
+ /**
3
+ * Minimal wrapper that adds reactive `interactions` to RoolSpace.
4
+ * All other properties and methods are proxied to the underlying space.
5
+ */
6
+ declare class ReactiveSpaceImpl {
18
7
  #private;
19
- info: SpaceInfo;
20
- conversationId: string;
21
- conversations: ConversationInfo[] | undefined;
22
- conversationsLoading: boolean;
23
- conversationsError: Error | null;
24
8
  interactions: Interaction[];
25
- systemInstruction: string | undefined;
26
9
  constructor(space: RoolSpace);
27
- setConversationId(id: string): void;
28
- setSystemInstruction(instruction: string | null): Promise<void>;
29
- refreshConversations(): Promise<void>;
30
- object(id: string): AsyncValue<RoolObject>;
31
- children(id: string, relation: string): AsyncValue<RoolObject[]>;
32
- parents(id: string, relation: string): AsyncValue<RoolObject[]>;
33
- query(options: FindObjectsOptions): AsyncValue<RoolObject[]>;
34
- createObject(options: CreateObjectOptions): Promise<{
35
- object: RoolObject;
10
+ get id(): string;
11
+ get name(): string;
12
+ get role(): import("@rool-dev/sdk").RoolUserRole;
13
+ get userId(): string;
14
+ get conversationId(): string;
15
+ set conversationId(id: string);
16
+ close(): void;
17
+ getObject(...args: Parameters<RoolSpace['getObject']>): Promise<import("@rool-dev/sdk").RoolObject | undefined>;
18
+ stat(...args: Parameters<RoolSpace['stat']>): Promise<import("@rool-dev/sdk").RoolObjectStat | undefined>;
19
+ findObjects(...args: Parameters<RoolSpace['findObjects']>): Promise<{
20
+ objects: import("@rool-dev/sdk").RoolObject[];
36
21
  message: string;
37
22
  }>;
38
- updateObject(objectId: string, options: UpdateObjectOptions): Promise<{
39
- object: RoolObject;
23
+ getObjectIds(...args: Parameters<RoolSpace['getObjectIds']>): string[];
24
+ createObject(...args: Parameters<RoolSpace['createObject']>): Promise<{
25
+ object: import("@rool-dev/sdk").RoolObject;
40
26
  message: string;
41
27
  }>;
42
- deleteObjects(objectIds: string[]): Promise<void>;
43
- link(sourceId: string, relation: string, targetId: string): Promise<void>;
44
- unlink(sourceId: string, relation?: string, targetId?: string): Promise<boolean>;
45
- prompt(text: string, options?: PromptOptions): Promise<{
28
+ updateObject(...args: Parameters<RoolSpace['updateObject']>): Promise<{
29
+ object: import("@rool-dev/sdk").RoolObject;
46
30
  message: string;
47
- objects: RoolObject[];
48
31
  }>;
49
- checkpoint(label?: string): Promise<string>;
32
+ deleteObjects(...args: Parameters<RoolSpace['deleteObjects']>): Promise<void>;
33
+ link(...args: Parameters<RoolSpace['link']>): Promise<void>;
34
+ unlink(...args: Parameters<RoolSpace['unlink']>): Promise<boolean>;
35
+ getParents(...args: Parameters<RoolSpace['getParents']>): Promise<import("@rool-dev/sdk").RoolObject[]>;
36
+ getChildren(...args: Parameters<RoolSpace['getChildren']>): Promise<import("@rool-dev/sdk").RoolObject[]>;
37
+ prompt(...args: Parameters<RoolSpace['prompt']>): Promise<{
38
+ message: string;
39
+ objects: import("@rool-dev/sdk").RoolObject[];
40
+ }>;
41
+ checkpoint(...args: Parameters<RoolSpace['checkpoint']>): Promise<string>;
42
+ canUndo(): Promise<boolean>;
43
+ canRedo(): Promise<boolean>;
50
44
  undo(): Promise<boolean>;
51
45
  redo(): Promise<boolean>;
52
- deleteConversation(conversationId?: string): Promise<void>;
53
- renameConversation(conversationId: string, name: string): Promise<void>;
54
- close(): void;
46
+ clearHistory(): Promise<void>;
47
+ setMetadata(...args: Parameters<RoolSpace['setMetadata']>): void;
48
+ getMetadata(...args: Parameters<RoolSpace['getMetadata']>): unknown;
49
+ getAllMetadata(): Record<string, unknown>;
50
+ getInteractions(): Interaction[];
51
+ getInteractionsById(...args: Parameters<RoolSpace['getInteractionsById']>): Interaction[];
52
+ getConversationIds(): string[];
53
+ deleteConversation(...args: Parameters<RoolSpace['deleteConversation']>): Promise<void>;
54
+ renameConversation(...args: Parameters<RoolSpace['renameConversation']>): Promise<void>;
55
+ listConversations(): Promise<import("@rool-dev/sdk").ConversationInfo[]>;
56
+ getSystemInstruction(): string | undefined;
57
+ setSystemInstruction(...args: Parameters<RoolSpace['setSystemInstruction']>): Promise<void>;
58
+ uploadMedia(...args: Parameters<RoolSpace['uploadMedia']>): Promise<string>;
59
+ fetchMedia(...args: Parameters<RoolSpace['fetchMedia']>): Promise<import("@rool-dev/sdk").MediaResponse>;
60
+ deleteMedia(...args: Parameters<RoolSpace['deleteMedia']>): Promise<void>;
61
+ listMedia(): Promise<import("@rool-dev/sdk").MediaInfo[]>;
62
+ exportArchive(): Promise<Blob>;
63
+ on(...args: Parameters<RoolSpace['on']>): () => void;
64
+ off(...args: Parameters<RoolSpace['off']>): void;
65
+ rename(...args: Parameters<RoolSpace['rename']>): Promise<void>;
66
+ getData(): import("@rool-dev/sdk").RoolSpaceData;
67
+ get isReadOnly(): boolean;
68
+ addUser(...args: Parameters<RoolSpace['addUser']>): Promise<void>;
69
+ removeUser(...args: Parameters<RoolSpace['removeUser']>): Promise<void>;
70
+ listUsers(): Promise<import("@rool-dev/sdk").SpaceMember[]>;
55
71
  }
56
- /**
57
- * Create a SpaceHandle from a RoolSpace instance.
58
- */
59
- export declare function createSpaceHandle(space: RoolSpace): SpaceHandle;
60
- export type SpaceHandle = SpaceHandleImpl;
72
+ export declare function wrapSpace(space: RoolSpace): ReactiveSpace;
73
+ export type ReactiveSpace = ReactiveSpaceImpl;
61
74
  export {};
62
75
  //# sourceMappingURL=space.svelte.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"space.svelte.d.ts","sourceRoot":"","sources":["../src/space.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACb,MAAM,eAAe,CAAC;AAMvB,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,YAAY,CAAC;CACpB;AAMD,qBAAa,UAAU,CAAC,CAAC;;IACvB,KAAK,gBAAoC;IACzC,OAAO,UAAiB;IACxB,KAAK,eAA8B;gBAIvB,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,aAAa,UAAO;IAOrD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAY9B,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,IAAI;IAK/B,KAAK,IAAI,IAAI;CAKd;AAMD,cAAM,eAAe;;IAWnB,IAAI,YAA2D;IAC/D,cAAc,SAAc;IAC5B,aAAa,iCAAqD;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Aa,CAAC,CAAC;IACzD,SAAS;IAGT,aAAa;IAGb,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACvC,GAAG,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAGzC,MAAM,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC/C,OAAO;IACP,IAAI,UAAU,YAAqC;IACnD,OAAO,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACjD,UAAU,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IACvD,SAAS;CACV;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,aAAa,CAEzD;AAED,MAAM,MAAM,aAAa,GAAG,iBAAiB,CAAC"}
@@ -1,318 +1,94 @@
1
- // ===========================================================================
2
- // AsyncValue - reactive async data wrapper
3
- // ===========================================================================
4
- export class AsyncValue {
5
- value = $state(undefined);
6
- loading = $state(false);
7
- error = $state(null);
8
- #fetcher;
9
- constructor(fetcher, fetchOnCreate = true) {
10
- this.#fetcher = fetcher;
11
- if (fetchOnCreate) {
12
- this.refresh();
13
- }
14
- }
15
- async refresh() {
16
- this.loading = true;
17
- this.error = null;
18
- try {
19
- this.value = await this.#fetcher();
20
- }
21
- catch (e) {
22
- this.error = e;
23
- }
24
- finally {
25
- this.loading = false;
26
- }
27
- }
28
- set(value) {
29
- this.value = value;
30
- this.error = null;
31
- }
32
- clear() {
33
- this.value = undefined;
34
- this.loading = false;
35
- this.error = null;
36
- }
37
- }
38
- // ===========================================================================
39
- // SpaceHandle - reactive space wrapper
40
- // ===========================================================================
41
- class SpaceHandleImpl {
1
+ /**
2
+ * Minimal wrapper that adds reactive `interactions` to RoolSpace.
3
+ * All other properties and methods are proxied to the underlying space.
4
+ */
5
+ class ReactiveSpaceImpl {
42
6
  #space;
43
7
  #unsubscribers = [];
44
- // Store caches
45
- #objectCache = new Map();
46
- #childrenCache = new Map();
47
- #parentsCache = new Map();
48
- #queryCache = new Map();
49
8
  // Reactive state
50
- info = $state({ id: '', name: '', role: 'viewer' });
51
- conversationId = $state('');
52
- conversations = $state(undefined);
53
- conversationsLoading = $state(false);
54
- conversationsError = $state(null);
55
9
  interactions = $state([]);
56
- systemInstruction = $state(undefined);
57
10
  constructor(space) {
58
11
  this.#space = space;
59
- // Initialize state
60
- this.info = {
61
- id: space.id,
62
- name: space.name,
63
- role: space.role,
64
- };
65
- this.conversationId = space.conversationId;
66
12
  this.interactions = space.getInteractions();
67
- this.systemInstruction = space.getSystemInstruction();
68
- // Initial fetches
69
- this.#refreshConversations();
70
- // Setup event listeners
71
- this.#setupEventListeners();
72
- }
73
- #setupEventListeners() {
74
- // Object events
75
- const onObjectCreated = (event) => {
76
- const store = this.#objectCache.get(event.objectId);
77
- if (store) {
78
- store.set(event.object);
79
- }
80
- };
81
- this.#space.on('objectCreated', onObjectCreated);
82
- this.#unsubscribers.push(() => this.#space.off('objectCreated', onObjectCreated));
83
- const onObjectUpdated = (event) => {
84
- const store = this.#objectCache.get(event.objectId);
85
- if (store) {
86
- store.set(event.object);
87
- }
88
- this.#refreshRelationStoresForObject(event.objectId);
13
+ // Subscribe to conversation updates
14
+ const onConversationUpdated = () => {
15
+ this.interactions = space.getInteractions();
89
16
  };
90
- this.#space.on('objectUpdated', onObjectUpdated);
91
- this.#unsubscribers.push(() => this.#space.off('objectUpdated', onObjectUpdated));
92
- const onObjectDeleted = (event) => {
93
- const store = this.#objectCache.get(event.objectId);
94
- if (store) {
95
- store.set(undefined);
96
- }
97
- this.#refreshRelationStoresForObject(event.objectId);
98
- };
99
- this.#space.on('objectDeleted', onObjectDeleted);
100
- this.#unsubscribers.push(() => this.#space.off('objectDeleted', onObjectDeleted));
101
- // Link events
102
- const onLinked = (event) => {
103
- const childrenKey = JSON.stringify([event.sourceId, event.relation]);
104
- this.#childrenCache.get(childrenKey)?.refresh();
105
- const parentsKey = JSON.stringify([event.targetId, event.relation]);
106
- this.#parentsCache.get(parentsKey)?.refresh();
107
- };
108
- this.#space.on('linked', onLinked);
109
- this.#unsubscribers.push(() => this.#space.off('linked', onLinked));
110
- const onUnlinked = (event) => {
111
- const childrenKey = JSON.stringify([event.sourceId, event.relation]);
112
- this.#childrenCache.get(childrenKey)?.refresh();
113
- const parentsKey = JSON.stringify([event.targetId, event.relation]);
114
- this.#parentsCache.get(parentsKey)?.refresh();
115
- };
116
- this.#space.on('unlinked', onUnlinked);
117
- this.#unsubscribers.push(() => this.#space.off('unlinked', onUnlinked));
118
- // Conversation events
119
- const onConversationUpdated = (event) => {
120
- if (event.conversationId === this.conversationId) {
121
- this.interactions = this.#space.getInteractions();
122
- this.systemInstruction = this.#space.getSystemInstruction();
123
- }
124
- };
125
- this.#space.on('conversationUpdated', onConversationUpdated);
126
- this.#unsubscribers.push(() => this.#space.off('conversationUpdated', onConversationUpdated));
127
- const onConversationsChanged = () => {
128
- this.#refreshConversations();
129
- };
130
- this.#space.on('conversationsChanged', onConversationsChanged);
131
- this.#unsubscribers.push(() => this.#space.off('conversationsChanged', onConversationsChanged));
132
- const onConversationIdChanged = (event) => {
133
- this.conversationId = event.newConversationId;
134
- this.interactions = this.#space.getInteractions();
135
- this.systemInstruction = this.#space.getSystemInstruction();
136
- };
137
- this.#space.on('conversationIdChanged', onConversationIdChanged);
138
- this.#unsubscribers.push(() => this.#space.off('conversationIdChanged', onConversationIdChanged));
139
- // Reset event (undo/redo, resync)
17
+ space.on('conversationUpdated', onConversationUpdated);
18
+ this.#unsubscribers.push(() => space.off('conversationUpdated', onConversationUpdated));
140
19
  const onReset = () => {
141
- for (const store of this.#objectCache.values()) {
142
- store.refresh();
143
- }
144
- for (const store of this.#childrenCache.values()) {
145
- store.refresh();
146
- }
147
- for (const store of this.#parentsCache.values()) {
148
- store.refresh();
149
- }
150
- for (const store of this.#queryCache.values()) {
151
- store.refresh();
152
- }
153
- this.#refreshConversations();
154
- this.interactions = this.#space.getInteractions();
155
- this.systemInstruction = this.#space.getSystemInstruction();
20
+ this.interactions = space.getInteractions();
156
21
  };
157
- this.#space.on('reset', onReset);
158
- this.#unsubscribers.push(() => this.#space.off('reset', onReset));
159
- }
160
- async #refreshConversations() {
161
- this.conversationsLoading = true;
162
- this.conversationsError = null;
163
- try {
164
- this.conversations = await this.#space.listConversations();
165
- }
166
- catch (e) {
167
- this.conversationsError = e;
168
- }
169
- finally {
170
- this.conversationsLoading = false;
171
- }
172
- }
173
- #refreshRelationStoresForObject(objectId) {
174
- for (const store of this.#childrenCache.values()) {
175
- if (store.value?.some((obj) => obj.id === objectId)) {
176
- store.refresh();
177
- }
178
- }
179
- for (const store of this.#parentsCache.values()) {
180
- if (store.value?.some((obj) => obj.id === objectId)) {
181
- store.refresh();
182
- }
183
- }
184
- }
185
- // ===========================================================================
186
- // Conversation management
187
- // ===========================================================================
188
- setConversationId(id) {
189
- if (id !== this.conversationId) {
190
- this.#space.conversationId = id;
191
- // Note: conversationIdChanged event will update our state
192
- }
193
- }
194
- async setSystemInstruction(instruction) {
195
- await this.#space.setSystemInstruction(instruction);
196
- this.systemInstruction = instruction ?? undefined;
197
- }
198
- refreshConversations() {
199
- return this.#refreshConversations();
200
- }
201
- // ===========================================================================
202
- // Object store factories
203
- // ===========================================================================
204
- object(id) {
205
- const cached = this.#objectCache.get(id);
206
- if (cached)
207
- return cached;
208
- const store = new AsyncValue(async () => {
209
- const obj = await this.#space.getObject(id);
210
- if (!obj)
211
- throw new Error(`Object not found: ${id}`);
212
- return obj;
213
- });
214
- this.#objectCache.set(id, store);
215
- return store;
216
- }
217
- children(id, relation) {
218
- const key = JSON.stringify([id, relation]);
219
- const cached = this.#childrenCache.get(key);
220
- if (cached)
221
- return cached;
222
- const store = new AsyncValue(() => this.#space.getChildren(id, relation));
223
- this.#childrenCache.set(key, store);
224
- return store;
225
- }
226
- parents(id, relation) {
227
- const key = JSON.stringify([id, relation]);
228
- const cached = this.#parentsCache.get(key);
229
- if (cached)
230
- return cached;
231
- const store = new AsyncValue(() => this.#space.getParents(id, relation));
232
- this.#parentsCache.set(key, store);
233
- return store;
234
- }
235
- query(options) {
236
- const key = JSON.stringify(options);
237
- const cached = this.#queryCache.get(key);
238
- if (cached)
239
- return cached;
240
- const store = new AsyncValue(async () => {
241
- const result = await this.#space.findObjects(options);
242
- return result.objects;
243
- });
244
- this.#queryCache.set(key, store);
245
- return store;
246
- }
247
- // ===========================================================================
248
- // Mutations (passthrough to SDK)
249
- // ===========================================================================
250
- createObject(options) {
251
- return this.#space.createObject(options);
252
- }
253
- updateObject(objectId, options) {
254
- return this.#space.updateObject(objectId, options);
255
- }
256
- deleteObjects(objectIds) {
257
- return this.#space.deleteObjects(objectIds);
258
- }
259
- link(sourceId, relation, targetId) {
260
- return this.#space.link(sourceId, relation, targetId);
261
- }
262
- unlink(sourceId, relation, targetId) {
263
- return this.#space.unlink(sourceId, relation, targetId);
264
- }
265
- prompt(text, options) {
266
- return this.#space.prompt(text, options);
267
- }
268
- checkpoint(label) {
269
- return this.#space.checkpoint(label);
270
- }
271
- undo() {
272
- return this.#space.undo();
273
- }
274
- redo() {
275
- return this.#space.redo();
276
- }
277
- // ===========================================================================
278
- // Conversation management (passthrough)
279
- // ===========================================================================
280
- deleteConversation(conversationId) {
281
- return this.#space.deleteConversation(conversationId);
282
- }
283
- renameConversation(conversationId, name) {
284
- return this.#space.renameConversation(conversationId, name);
285
- }
286
- // ===========================================================================
287
- // Cleanup
288
- // ===========================================================================
22
+ space.on('reset', onReset);
23
+ this.#unsubscribers.push(() => space.off('reset', onReset));
24
+ }
25
+ // Proxy read-only properties
26
+ get id() { return this.#space.id; }
27
+ get name() { return this.#space.name; }
28
+ get role() { return this.#space.role; }
29
+ get userId() { return this.#space.userId; }
30
+ get conversationId() { return this.#space.conversationId; }
31
+ set conversationId(id) { this.#space.conversationId = id; }
32
+ // Proxy all methods
289
33
  close() {
290
- for (const unsub of this.#unsubscribers) {
34
+ for (const unsub of this.#unsubscribers)
291
35
  unsub();
292
- }
293
36
  this.#unsubscribers.length = 0;
294
- for (const store of this.#objectCache.values()) {
295
- store.clear();
296
- }
297
- this.#objectCache.clear();
298
- for (const store of this.#childrenCache.values()) {
299
- store.clear();
300
- }
301
- this.#childrenCache.clear();
302
- for (const store of this.#parentsCache.values()) {
303
- store.clear();
304
- }
305
- this.#parentsCache.clear();
306
- for (const store of this.#queryCache.values()) {
307
- store.clear();
308
- }
309
- this.#queryCache.clear();
310
37
  this.#space.close();
311
38
  }
39
+ // Object operations
40
+ getObject(...args) { return this.#space.getObject(...args); }
41
+ stat(...args) { return this.#space.stat(...args); }
42
+ findObjects(...args) { return this.#space.findObjects(...args); }
43
+ getObjectIds(...args) { return this.#space.getObjectIds(...args); }
44
+ createObject(...args) { return this.#space.createObject(...args); }
45
+ updateObject(...args) { return this.#space.updateObject(...args); }
46
+ deleteObjects(...args) { return this.#space.deleteObjects(...args); }
47
+ // Relations
48
+ link(...args) { return this.#space.link(...args); }
49
+ unlink(...args) { return this.#space.unlink(...args); }
50
+ getParents(...args) { return this.#space.getParents(...args); }
51
+ getChildren(...args) { return this.#space.getChildren(...args); }
52
+ // AI
53
+ prompt(...args) { return this.#space.prompt(...args); }
54
+ // Undo/redo
55
+ checkpoint(...args) { return this.#space.checkpoint(...args); }
56
+ canUndo() { return this.#space.canUndo(); }
57
+ canRedo() { return this.#space.canRedo(); }
58
+ undo() { return this.#space.undo(); }
59
+ redo() { return this.#space.redo(); }
60
+ clearHistory() { return this.#space.clearHistory(); }
61
+ // Metadata
62
+ setMetadata(...args) { return this.#space.setMetadata(...args); }
63
+ getMetadata(...args) { return this.#space.getMetadata(...args); }
64
+ getAllMetadata() { return this.#space.getAllMetadata(); }
65
+ // Conversations
66
+ getInteractions() { return this.#space.getInteractions(); }
67
+ getInteractionsById(...args) { return this.#space.getInteractionsById(...args); }
68
+ getConversationIds() { return this.#space.getConversationIds(); }
69
+ deleteConversation(...args) { return this.#space.deleteConversation(...args); }
70
+ renameConversation(...args) { return this.#space.renameConversation(...args); }
71
+ listConversations() { return this.#space.listConversations(); }
72
+ getSystemInstruction() { return this.#space.getSystemInstruction(); }
73
+ setSystemInstruction(...args) { return this.#space.setSystemInstruction(...args); }
74
+ // Media
75
+ uploadMedia(...args) { return this.#space.uploadMedia(...args); }
76
+ fetchMedia(...args) { return this.#space.fetchMedia(...args); }
77
+ deleteMedia(...args) { return this.#space.deleteMedia(...args); }
78
+ listMedia() { return this.#space.listMedia(); }
79
+ // Export/import
80
+ exportArchive() { return this.#space.exportArchive(); }
81
+ // Events
82
+ on(...args) { return this.#space.on(...args); }
83
+ off(...args) { return this.#space.off(...args); }
84
+ // Advanced
85
+ rename(...args) { return this.#space.rename(...args); }
86
+ getData() { return this.#space.getData(); }
87
+ get isReadOnly() { return this.#space.isReadOnly; }
88
+ addUser(...args) { return this.#space.addUser(...args); }
89
+ removeUser(...args) { return this.#space.removeUser(...args); }
90
+ listUsers() { return this.#space.listUsers(); }
312
91
  }
313
- /**
314
- * Create a SpaceHandle from a RoolSpace instance.
315
- */
316
- export function createSpaceHandle(space) {
317
- return new SpaceHandleImpl(space);
92
+ export function wrapSpace(space) {
93
+ return new ReactiveSpaceImpl(space);
318
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rool-dev/svelte",
3
- "version": "0.1.4",
3
+ "version": "0.1.6-dev.fdaf8f8",
4
4
  "description": "Svelte 5 runes for Rool Spaces",
5
5
  "type": "module",
6
6
  "svelte": "./dist/index.js",
package/dist/types.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export type { RoolSpaceInfo, RoolObject, RoolUserRole, ConnectionState, ConversationInfo, Interaction, FindObjectsOptions, PromptOptions, CreateObjectOptions, UpdateObjectOptions, } from '@rool-dev/sdk';
2
- export type { Rool } from './rool.svelte.js';
3
- export type { SpaceHandle, SpaceInfo, AsyncValue } from './space.svelte.js';
4
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,YAAY,EACV,aAAa,EACb,UAAU,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAGvB,YAAY,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export {};