@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 +82 -143
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/rool.svelte.d.ts +32 -5
- package/dist/rool.svelte.d.ts.map +1 -1
- package/dist/rool.svelte.js +38 -36
- package/dist/space.svelte.d.ts +61 -48
- package/dist/space.svelte.d.ts.map +1 -1
- package/dist/space.svelte.js +77 -301
- package/package.json +1 -1
- package/dist/types.d.ts +0 -4
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Rool Svelte
|
|
2
2
|
|
|
3
|
-
Svelte 5 bindings for Rool Spaces.
|
|
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](
|
|
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
|
|
69
|
+
### Client State
|
|
49
70
|
|
|
50
71
|
```svelte
|
|
51
72
|
<script>
|
|
52
|
-
//
|
|
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
|
-
###
|
|
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
|
-
###
|
|
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
|
-
|
|
109
|
+
`openSpace` and `createSpace` return a `ReactiveSpace` — the SDK's `RoolSpace` with reactive `interactions`:
|
|
124
110
|
|
|
125
111
|
```svelte
|
|
126
112
|
<script>
|
|
127
|
-
|
|
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
|
-
|
|
140
|
-
|
|
115
|
+
async function open(id) {
|
|
116
|
+
space = await rool.openSpace(id);
|
|
117
|
+
}
|
|
141
118
|
</script>
|
|
142
119
|
|
|
143
|
-
{#if
|
|
144
|
-
|
|
145
|
-
{
|
|
146
|
-
|
|
147
|
-
{
|
|
148
|
-
|
|
149
|
-
{/
|
|
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
|
-
<!--
|
|
152
|
-
<button onclick={() =>
|
|
128
|
+
<!-- All SDK methods work directly -->
|
|
129
|
+
<button onclick={() => space.prompt('Hello')}>Send</button>
|
|
130
|
+
{/if}
|
|
153
131
|
```
|
|
154
132
|
|
|
155
|
-
###
|
|
133
|
+
### Using the SDK
|
|
156
134
|
|
|
157
|
-
All
|
|
135
|
+
All `RoolSpace` methods and properties are available on `ReactiveSpace`:
|
|
158
136
|
|
|
159
137
|
```typescript
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
await space.
|
|
172
|
-
|
|
173
|
-
//
|
|
174
|
-
await space.link(sourceId, 'references', targetId)
|
|
175
|
-
await space.unlink(sourceId, 'references', targetId)
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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.
|
|
185
|
-
await space.
|
|
186
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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
package/dist/rool.svelte.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { type RoolSpaceInfo, type ConnectionState } from '@rool-dev/sdk';
|
|
2
|
-
import { type
|
|
2
|
+
import { type ReactiveSpace } from './space.svelte.js';
|
|
3
3
|
/**
|
|
4
|
-
* Rool client with reactive state
|
|
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<
|
|
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<
|
|
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():
|
|
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,
|
|
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"}
|
package/dist/rool.svelte.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { RoolClient } from '@rool-dev/sdk';
|
|
2
|
-
import {
|
|
2
|
+
import { wrapSpace } from './space.svelte.js';
|
|
3
3
|
/**
|
|
4
|
-
* Rool client with reactive state
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
83
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Open an existing space. Returns a ReactiveSpace with reactive `interactions`.
|
|
94
|
+
*/
|
|
84
95
|
async openSpace(id, options) {
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
this.#openSpaces.add(
|
|
88
|
-
|
|
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
|
|
98
|
-
const
|
|
99
|
-
this.#openSpaces.add(
|
|
100
|
-
|
|
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
|
-
|
|
110
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Manually refresh the spaces list.
|
|
112
|
+
*/
|
|
111
113
|
refreshSpaces() {
|
|
112
114
|
return this.#refreshSpaces();
|
|
113
115
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Clean up resources.
|
|
118
|
+
*/
|
|
117
119
|
destroy() {
|
|
118
120
|
for (const space of this.#openSpaces) {
|
|
119
121
|
space.close();
|
package/dist/space.svelte.d.ts
CHANGED
|
@@ -1,62 +1,75 @@
|
|
|
1
|
-
import type { RoolSpace,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
39
|
-
|
|
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
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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,
|
|
1
|
+
{"version":3,"file":"space.svelte.d.ts","sourceRoot":"","sources":["../src/space.svelte.ts"],"names":[],"mappings":"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"}
|
package/dist/space.svelte.js
CHANGED
|
@@ -1,318 +1,94 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
91
|
-
this.#unsubscribers.push(() =>
|
|
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
|
-
|
|
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
|
-
|
|
158
|
-
this.#unsubscribers.push(() =>
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
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
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
|
package/dist/types.d.ts.map
DELETED
|
@@ -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 {};
|