@rool-dev/svelte 0.2.0-dev.f798776 → 0.3.0-dev.5070a39
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 +165 -54
- package/dist/channel.svelte.d.ts +143 -0
- package/dist/channel.svelte.d.ts.map +1 -0
- package/dist/channel.svelte.js +343 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/rool.svelte.d.ts +31 -16
- package/dist/rool.svelte.d.ts.map +1 -1
- package/dist/rool.svelte.js +51 -28
- package/package.json +2 -2
- package/dist/space.svelte.d.ts +0 -144
- package/dist/space.svelte.d.ts.map +0 -1
- package/dist/space.svelte.js +0 -311
package/dist/space.svelte.d.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import type { RoolSpace, Interaction, RoolObject, ConversationInfo } from '@rool-dev/sdk';
|
|
2
|
-
/**
|
|
3
|
-
* Options for creating a reactive collection.
|
|
4
|
-
* Same as FindObjectsOptions but without `prompt` (AI queries are too slow for reactive updates).
|
|
5
|
-
*/
|
|
6
|
-
export interface CollectionOptions {
|
|
7
|
-
/** Field requirements for exact matching */
|
|
8
|
-
where?: Record<string, unknown>;
|
|
9
|
-
/** Maximum number of objects */
|
|
10
|
-
limit?: number;
|
|
11
|
-
/** Sort order by modifiedAt: 'asc' or 'desc' (default: 'desc') */
|
|
12
|
-
order?: 'asc' | 'desc';
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* A reactive collection of objects that auto-updates when matching objects change.
|
|
16
|
-
*/
|
|
17
|
-
declare class ReactiveCollectionImpl {
|
|
18
|
-
#private;
|
|
19
|
-
objects: RoolObject[];
|
|
20
|
-
loading: boolean;
|
|
21
|
-
constructor(space: RoolSpace, options: CollectionOptions);
|
|
22
|
-
/**
|
|
23
|
-
* Re-fetch the collection from the space.
|
|
24
|
-
*/
|
|
25
|
-
refresh(): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Stop listening for updates and clean up.
|
|
28
|
-
*/
|
|
29
|
-
close(): void;
|
|
30
|
-
}
|
|
31
|
-
export type ReactiveCollection = ReactiveCollectionImpl;
|
|
32
|
-
/**
|
|
33
|
-
* A reactive single object that auto-updates when the object changes.
|
|
34
|
-
*/
|
|
35
|
-
declare class ReactiveObjectImpl {
|
|
36
|
-
#private;
|
|
37
|
-
data: RoolObject | undefined;
|
|
38
|
-
loading: boolean;
|
|
39
|
-
constructor(space: RoolSpace, objectId: string);
|
|
40
|
-
/**
|
|
41
|
-
* Re-fetch the object from the space.
|
|
42
|
-
*/
|
|
43
|
-
refresh(): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* Stop listening for updates and clean up.
|
|
46
|
-
*/
|
|
47
|
-
close(): void;
|
|
48
|
-
}
|
|
49
|
-
export type ReactiveObject = ReactiveObjectImpl;
|
|
50
|
-
/**
|
|
51
|
-
* Minimal wrapper that adds reactive `interactions` to RoolSpace.
|
|
52
|
-
* All other properties and methods are proxied to the underlying space.
|
|
53
|
-
*/
|
|
54
|
-
declare class ReactiveSpaceImpl {
|
|
55
|
-
#private;
|
|
56
|
-
interactions: Interaction[];
|
|
57
|
-
conversations: ConversationInfo[];
|
|
58
|
-
constructor(space: RoolSpace);
|
|
59
|
-
get id(): string;
|
|
60
|
-
get name(): string;
|
|
61
|
-
get role(): import("@rool-dev/sdk").RoolUserRole;
|
|
62
|
-
get userId(): string;
|
|
63
|
-
get conversationId(): string;
|
|
64
|
-
set conversationId(id: string);
|
|
65
|
-
close(): void;
|
|
66
|
-
getObject(...args: Parameters<RoolSpace['getObject']>): Promise<RoolObject | undefined>;
|
|
67
|
-
stat(...args: Parameters<RoolSpace['stat']>): Promise<import("@rool-dev/sdk").RoolObjectStat | undefined>;
|
|
68
|
-
findObjects(...args: Parameters<RoolSpace['findObjects']>): Promise<{
|
|
69
|
-
objects: RoolObject[];
|
|
70
|
-
message: string;
|
|
71
|
-
}>;
|
|
72
|
-
getObjectIds(...args: Parameters<RoolSpace['getObjectIds']>): string[];
|
|
73
|
-
createObject(...args: Parameters<RoolSpace['createObject']>): Promise<{
|
|
74
|
-
object: RoolObject;
|
|
75
|
-
message: string;
|
|
76
|
-
}>;
|
|
77
|
-
updateObject(...args: Parameters<RoolSpace['updateObject']>): Promise<{
|
|
78
|
-
object: RoolObject;
|
|
79
|
-
message: string;
|
|
80
|
-
}>;
|
|
81
|
-
deleteObjects(...args: Parameters<RoolSpace['deleteObjects']>): Promise<void>;
|
|
82
|
-
prompt(...args: Parameters<RoolSpace['prompt']>): Promise<{
|
|
83
|
-
message: string;
|
|
84
|
-
objects: RoolObject[];
|
|
85
|
-
}>;
|
|
86
|
-
checkpoint(...args: Parameters<RoolSpace['checkpoint']>): Promise<string>;
|
|
87
|
-
canUndo(): Promise<boolean>;
|
|
88
|
-
canRedo(): Promise<boolean>;
|
|
89
|
-
undo(): Promise<boolean>;
|
|
90
|
-
redo(): Promise<boolean>;
|
|
91
|
-
clearHistory(): Promise<void>;
|
|
92
|
-
setMetadata(...args: Parameters<RoolSpace['setMetadata']>): void;
|
|
93
|
-
getMetadata(...args: Parameters<RoolSpace['getMetadata']>): unknown;
|
|
94
|
-
getAllMetadata(): Record<string, unknown>;
|
|
95
|
-
getInteractions(): Interaction[];
|
|
96
|
-
getInteractionsById(...args: Parameters<RoolSpace['getInteractionsById']>): Interaction[];
|
|
97
|
-
getConversationIds(): string[];
|
|
98
|
-
deleteConversation(...args: Parameters<RoolSpace['deleteConversation']>): Promise<void>;
|
|
99
|
-
renameConversation(...args: Parameters<RoolSpace['renameConversation']>): Promise<void>;
|
|
100
|
-
listConversations(): Promise<ConversationInfo[]>;
|
|
101
|
-
getSystemInstruction(): string | undefined;
|
|
102
|
-
setSystemInstruction(...args: Parameters<RoolSpace['setSystemInstruction']>): Promise<void>;
|
|
103
|
-
uploadMedia(...args: Parameters<RoolSpace['uploadMedia']>): Promise<string>;
|
|
104
|
-
fetchMedia(...args: Parameters<RoolSpace['fetchMedia']>): Promise<import("@rool-dev/sdk").MediaResponse>;
|
|
105
|
-
deleteMedia(...args: Parameters<RoolSpace['deleteMedia']>): Promise<void>;
|
|
106
|
-
listMedia(): Promise<import("@rool-dev/sdk").MediaInfo[]>;
|
|
107
|
-
exportArchive(): Promise<Blob>;
|
|
108
|
-
on(...args: Parameters<RoolSpace['on']>): () => void;
|
|
109
|
-
off(...args: Parameters<RoolSpace['off']>): void;
|
|
110
|
-
/**
|
|
111
|
-
* Create a reactive object that auto-updates when the object changes.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* const article = space.object('article-123');
|
|
115
|
-
* // article.data is reactive (RoolObject | undefined)
|
|
116
|
-
* // article.loading indicates fetch status
|
|
117
|
-
* // article.refresh() to manually re-fetch
|
|
118
|
-
* // article.close() to stop listening
|
|
119
|
-
*/
|
|
120
|
-
object(objectId: string): ReactiveObject;
|
|
121
|
-
/**
|
|
122
|
-
* Create a reactive collection that auto-updates when matching objects change.
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* const articles = space.collection({ where: { type: 'article' } });
|
|
126
|
-
* // articles.objects is reactive
|
|
127
|
-
* // articles.loading indicates fetch status
|
|
128
|
-
* // articles.refresh() to manually re-fetch
|
|
129
|
-
* // articles.close() to stop listening
|
|
130
|
-
*/
|
|
131
|
-
collection(options: CollectionOptions): ReactiveCollection;
|
|
132
|
-
rename(...args: Parameters<RoolSpace['rename']>): Promise<void>;
|
|
133
|
-
getData(): import("@rool-dev/sdk").RoolSpaceData;
|
|
134
|
-
get isReadOnly(): boolean;
|
|
135
|
-
addUser(...args: Parameters<RoolSpace['addUser']>): Promise<void>;
|
|
136
|
-
removeUser(...args: Parameters<RoolSpace['removeUser']>): Promise<void>;
|
|
137
|
-
listUsers(): Promise<import("@rool-dev/sdk").SpaceMember[]>;
|
|
138
|
-
setLinkAccess(...args: Parameters<RoolSpace['setLinkAccess']>): Promise<void>;
|
|
139
|
-
get linkAccess(): import("@rool-dev/sdk").LinkAccess;
|
|
140
|
-
}
|
|
141
|
-
export declare function wrapSpace(space: RoolSpace): ReactiveSpace;
|
|
142
|
-
export type ReactiveSpace = ReactiveSpaceImpl;
|
|
143
|
-
export {};
|
|
144
|
-
//# sourceMappingURL=space.svelte.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"space.svelte.d.ts","sourceRoot":"","sources":["../src/space.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAsB,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE9G;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,gCAAgC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,cAAM,sBAAsB;;IAO1B,OAAO,eAA4B;IACnC,OAAO,UAAgB;gBAEX,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,iBAAiB;IAqExD;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAiB9B;;OAEG;IACH,KAAK,IAAI,IAAI;CAId;AAED,MAAM,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AAExD;;GAEG;AACH,cAAM,kBAAkB;;IAMtB,IAAI,yBAA6C;IACjD,OAAO,UAAgB;gBAEX,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM;IA2C9C;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAS9B;;OAEG;IACH,KAAK,IAAI,IAAI;CAId;AAED,MAAM,MAAM,cAAc,GAAG,kBAAkB,CAAC;AAEhD;;;GAGG;AACH,cAAM,iBAAiB;;IAKrB,YAAY,gBAA6B;IACzC,aAAa,q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CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;IAC7D,IAAI,UAAU,uCAAqC;CACpD;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,aAAa,CAEzD;AAED,MAAM,MAAM,aAAa,GAAG,iBAAiB,CAAC"}
|
package/dist/space.svelte.js
DELETED
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A reactive collection of objects that auto-updates when matching objects change.
|
|
3
|
-
*/
|
|
4
|
-
class ReactiveCollectionImpl {
|
|
5
|
-
#space;
|
|
6
|
-
#options;
|
|
7
|
-
#unsubscribers = [];
|
|
8
|
-
#currentIds = new Set();
|
|
9
|
-
// Reactive state
|
|
10
|
-
objects = $state([]);
|
|
11
|
-
loading = $state(true);
|
|
12
|
-
constructor(space, options) {
|
|
13
|
-
this.#space = space;
|
|
14
|
-
this.#options = options;
|
|
15
|
-
this.#setup();
|
|
16
|
-
}
|
|
17
|
-
#setup() {
|
|
18
|
-
// Initial fetch
|
|
19
|
-
this.refresh();
|
|
20
|
-
// Subscribe to object events
|
|
21
|
-
const onObjectCreated = ({ object }) => {
|
|
22
|
-
if (this.#matches(object)) {
|
|
23
|
-
this.refresh();
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
this.#space.on('objectCreated', onObjectCreated);
|
|
27
|
-
this.#unsubscribers.push(() => this.#space.off('objectCreated', onObjectCreated));
|
|
28
|
-
const onObjectUpdated = ({ objectId, object }) => {
|
|
29
|
-
const wasInCollection = this.#currentIds.has(objectId);
|
|
30
|
-
const nowMatches = this.#matches(object);
|
|
31
|
-
if (wasInCollection && nowMatches) {
|
|
32
|
-
// Update in place
|
|
33
|
-
const index = this.objects.findIndex((o) => o.id === objectId);
|
|
34
|
-
if (index !== -1) {
|
|
35
|
-
this.objects[index] = object;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else if (wasInCollection && !nowMatches) {
|
|
39
|
-
// Remove from collection
|
|
40
|
-
this.objects = this.objects.filter((o) => o.id !== objectId);
|
|
41
|
-
this.#currentIds.delete(objectId);
|
|
42
|
-
}
|
|
43
|
-
else if (!wasInCollection && nowMatches) {
|
|
44
|
-
// Add to collection (re-fetch to respect limit/order)
|
|
45
|
-
this.refresh();
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
this.#space.on('objectUpdated', onObjectUpdated);
|
|
49
|
-
this.#unsubscribers.push(() => this.#space.off('objectUpdated', onObjectUpdated));
|
|
50
|
-
const onObjectDeleted = ({ objectId }) => {
|
|
51
|
-
if (this.#currentIds.has(objectId)) {
|
|
52
|
-
this.objects = this.objects.filter((o) => o.id !== objectId);
|
|
53
|
-
this.#currentIds.delete(objectId);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
this.#space.on('objectDeleted', onObjectDeleted);
|
|
57
|
-
this.#unsubscribers.push(() => this.#space.off('objectDeleted', onObjectDeleted));
|
|
58
|
-
// Handle full resets
|
|
59
|
-
const onReset = () => this.refresh();
|
|
60
|
-
this.#space.on('reset', onReset);
|
|
61
|
-
this.#unsubscribers.push(() => this.#space.off('reset', onReset));
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Check if an object matches the `where` filter.
|
|
65
|
-
*/
|
|
66
|
-
#matches(object) {
|
|
67
|
-
const where = this.#options.where;
|
|
68
|
-
if (!where)
|
|
69
|
-
return true;
|
|
70
|
-
for (const [key, value] of Object.entries(where)) {
|
|
71
|
-
if (object[key] !== value)
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Re-fetch the collection from the space.
|
|
78
|
-
*/
|
|
79
|
-
async refresh() {
|
|
80
|
-
this.loading = true;
|
|
81
|
-
try {
|
|
82
|
-
const findOptions = {
|
|
83
|
-
where: this.#options.where,
|
|
84
|
-
limit: this.#options.limit,
|
|
85
|
-
order: this.#options.order,
|
|
86
|
-
ephemeral: true, // Don't pollute conversation history
|
|
87
|
-
};
|
|
88
|
-
const { objects } = await this.#space.findObjects(findOptions);
|
|
89
|
-
this.objects = objects;
|
|
90
|
-
this.#currentIds = new Set(objects.map((o) => o.id));
|
|
91
|
-
}
|
|
92
|
-
finally {
|
|
93
|
-
this.loading = false;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Stop listening for updates and clean up.
|
|
98
|
-
*/
|
|
99
|
-
close() {
|
|
100
|
-
for (const unsub of this.#unsubscribers)
|
|
101
|
-
unsub();
|
|
102
|
-
this.#unsubscribers.length = 0;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* A reactive single object that auto-updates when the object changes.
|
|
107
|
-
*/
|
|
108
|
-
class ReactiveObjectImpl {
|
|
109
|
-
#space;
|
|
110
|
-
#objectId;
|
|
111
|
-
#unsubscribers = [];
|
|
112
|
-
// Reactive state
|
|
113
|
-
data = $state(undefined);
|
|
114
|
-
loading = $state(true);
|
|
115
|
-
constructor(space, objectId) {
|
|
116
|
-
this.#space = space;
|
|
117
|
-
this.#objectId = objectId;
|
|
118
|
-
this.#setup();
|
|
119
|
-
}
|
|
120
|
-
#setup() {
|
|
121
|
-
// Initial fetch
|
|
122
|
-
this.refresh();
|
|
123
|
-
// Listen for updates to this specific object
|
|
124
|
-
const onObjectUpdated = ({ objectId, object }) => {
|
|
125
|
-
if (objectId === this.#objectId) {
|
|
126
|
-
this.data = object;
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
this.#space.on('objectUpdated', onObjectUpdated);
|
|
130
|
-
this.#unsubscribers.push(() => this.#space.off('objectUpdated', onObjectUpdated));
|
|
131
|
-
// Listen for creation (in case object didn't exist initially)
|
|
132
|
-
const onObjectCreated = ({ object }) => {
|
|
133
|
-
if (object.id === this.#objectId) {
|
|
134
|
-
this.data = object;
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
this.#space.on('objectCreated', onObjectCreated);
|
|
138
|
-
this.#unsubscribers.push(() => this.#space.off('objectCreated', onObjectCreated));
|
|
139
|
-
// Listen for deletion
|
|
140
|
-
const onObjectDeleted = ({ objectId }) => {
|
|
141
|
-
if (objectId === this.#objectId) {
|
|
142
|
-
this.data = undefined;
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
this.#space.on('objectDeleted', onObjectDeleted);
|
|
146
|
-
this.#unsubscribers.push(() => this.#space.off('objectDeleted', onObjectDeleted));
|
|
147
|
-
// Handle full resets
|
|
148
|
-
const onReset = () => this.refresh();
|
|
149
|
-
this.#space.on('reset', onReset);
|
|
150
|
-
this.#unsubscribers.push(() => this.#space.off('reset', onReset));
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Re-fetch the object from the space.
|
|
154
|
-
*/
|
|
155
|
-
async refresh() {
|
|
156
|
-
this.loading = true;
|
|
157
|
-
try {
|
|
158
|
-
this.data = await this.#space.getObject(this.#objectId);
|
|
159
|
-
}
|
|
160
|
-
finally {
|
|
161
|
-
this.loading = false;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Stop listening for updates and clean up.
|
|
166
|
-
*/
|
|
167
|
-
close() {
|
|
168
|
-
for (const unsub of this.#unsubscribers)
|
|
169
|
-
unsub();
|
|
170
|
-
this.#unsubscribers.length = 0;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Minimal wrapper that adds reactive `interactions` to RoolSpace.
|
|
175
|
-
* All other properties and methods are proxied to the underlying space.
|
|
176
|
-
*/
|
|
177
|
-
class ReactiveSpaceImpl {
|
|
178
|
-
#space;
|
|
179
|
-
#unsubscribers = [];
|
|
180
|
-
// Reactive state
|
|
181
|
-
interactions = $state([]);
|
|
182
|
-
conversations = $state([]);
|
|
183
|
-
#conversationId = $state('');
|
|
184
|
-
constructor(space) {
|
|
185
|
-
this.#space = space;
|
|
186
|
-
this.interactions = space.getInteractions();
|
|
187
|
-
this.#conversationId = space.conversationId;
|
|
188
|
-
// Initial fetch of conversations (async)
|
|
189
|
-
this.#refreshConversations();
|
|
190
|
-
// Subscribe to conversation updates
|
|
191
|
-
const onConversationUpdated = () => {
|
|
192
|
-
this.interactions = space.getInteractions();
|
|
193
|
-
};
|
|
194
|
-
space.on('conversationUpdated', onConversationUpdated);
|
|
195
|
-
this.#unsubscribers.push(() => space.off('conversationUpdated', onConversationUpdated));
|
|
196
|
-
const onReset = () => {
|
|
197
|
-
this.interactions = space.getInteractions();
|
|
198
|
-
};
|
|
199
|
-
space.on('reset', onReset);
|
|
200
|
-
this.#unsubscribers.push(() => space.off('reset', onReset));
|
|
201
|
-
// Update interactions and conversationId when switching conversations
|
|
202
|
-
const onConversationIdChanged = () => {
|
|
203
|
-
this.#conversationId = space.conversationId;
|
|
204
|
-
this.interactions = space.getInteractions();
|
|
205
|
-
};
|
|
206
|
-
space.on('conversationIdChanged', onConversationIdChanged);
|
|
207
|
-
this.#unsubscribers.push(() => space.off('conversationIdChanged', onConversationIdChanged));
|
|
208
|
-
// Update conversations list when conversations change
|
|
209
|
-
const onConversationsChanged = () => {
|
|
210
|
-
this.#refreshConversations();
|
|
211
|
-
};
|
|
212
|
-
space.on('conversationsChanged', onConversationsChanged);
|
|
213
|
-
this.#unsubscribers.push(() => space.off('conversationsChanged', onConversationsChanged));
|
|
214
|
-
}
|
|
215
|
-
async #refreshConversations() {
|
|
216
|
-
this.conversations = await this.#space.listConversations();
|
|
217
|
-
}
|
|
218
|
-
// Proxy read-only properties
|
|
219
|
-
get id() { return this.#space.id; }
|
|
220
|
-
get name() { return this.#space.name; }
|
|
221
|
-
get role() { return this.#space.role; }
|
|
222
|
-
get userId() { return this.#space.userId; }
|
|
223
|
-
get conversationId() { return this.#conversationId; }
|
|
224
|
-
set conversationId(id) { this.#space.conversationId = id; }
|
|
225
|
-
// Proxy all methods
|
|
226
|
-
close() {
|
|
227
|
-
for (const unsub of this.#unsubscribers)
|
|
228
|
-
unsub();
|
|
229
|
-
this.#unsubscribers.length = 0;
|
|
230
|
-
this.#space.close();
|
|
231
|
-
}
|
|
232
|
-
// Object operations
|
|
233
|
-
getObject(...args) { return this.#space.getObject(...args); }
|
|
234
|
-
stat(...args) { return this.#space.stat(...args); }
|
|
235
|
-
findObjects(...args) { return this.#space.findObjects(...args); }
|
|
236
|
-
getObjectIds(...args) { return this.#space.getObjectIds(...args); }
|
|
237
|
-
createObject(...args) { return this.#space.createObject(...args); }
|
|
238
|
-
updateObject(...args) { return this.#space.updateObject(...args); }
|
|
239
|
-
deleteObjects(...args) { return this.#space.deleteObjects(...args); }
|
|
240
|
-
// AI
|
|
241
|
-
prompt(...args) { return this.#space.prompt(...args); }
|
|
242
|
-
// Undo/redo
|
|
243
|
-
checkpoint(...args) { return this.#space.checkpoint(...args); }
|
|
244
|
-
canUndo() { return this.#space.canUndo(); }
|
|
245
|
-
canRedo() { return this.#space.canRedo(); }
|
|
246
|
-
undo() { return this.#space.undo(); }
|
|
247
|
-
redo() { return this.#space.redo(); }
|
|
248
|
-
clearHistory() { return this.#space.clearHistory(); }
|
|
249
|
-
// Metadata
|
|
250
|
-
setMetadata(...args) { return this.#space.setMetadata(...args); }
|
|
251
|
-
getMetadata(...args) { return this.#space.getMetadata(...args); }
|
|
252
|
-
getAllMetadata() { return this.#space.getAllMetadata(); }
|
|
253
|
-
// Conversations
|
|
254
|
-
getInteractions() { return this.#space.getInteractions(); }
|
|
255
|
-
getInteractionsById(...args) { return this.#space.getInteractionsById(...args); }
|
|
256
|
-
getConversationIds() { return this.#space.getConversationIds(); }
|
|
257
|
-
deleteConversation(...args) { return this.#space.deleteConversation(...args); }
|
|
258
|
-
renameConversation(...args) { return this.#space.renameConversation(...args); }
|
|
259
|
-
listConversations() { return this.#space.listConversations(); }
|
|
260
|
-
getSystemInstruction() { return this.#space.getSystemInstruction(); }
|
|
261
|
-
setSystemInstruction(...args) { return this.#space.setSystemInstruction(...args); }
|
|
262
|
-
// Media
|
|
263
|
-
uploadMedia(...args) { return this.#space.uploadMedia(...args); }
|
|
264
|
-
fetchMedia(...args) { return this.#space.fetchMedia(...args); }
|
|
265
|
-
deleteMedia(...args) { return this.#space.deleteMedia(...args); }
|
|
266
|
-
listMedia() { return this.#space.listMedia(); }
|
|
267
|
-
// Export/import
|
|
268
|
-
exportArchive() { return this.#space.exportArchive(); }
|
|
269
|
-
// Events
|
|
270
|
-
on(...args) { return this.#space.on(...args); }
|
|
271
|
-
off(...args) { return this.#space.off(...args); }
|
|
272
|
-
// Reactive primitives
|
|
273
|
-
/**
|
|
274
|
-
* Create a reactive object that auto-updates when the object changes.
|
|
275
|
-
*
|
|
276
|
-
* @example
|
|
277
|
-
* const article = space.object('article-123');
|
|
278
|
-
* // article.data is reactive (RoolObject | undefined)
|
|
279
|
-
* // article.loading indicates fetch status
|
|
280
|
-
* // article.refresh() to manually re-fetch
|
|
281
|
-
* // article.close() to stop listening
|
|
282
|
-
*/
|
|
283
|
-
object(objectId) {
|
|
284
|
-
return new ReactiveObjectImpl(this.#space, objectId);
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Create a reactive collection that auto-updates when matching objects change.
|
|
288
|
-
*
|
|
289
|
-
* @example
|
|
290
|
-
* const articles = space.collection({ where: { type: 'article' } });
|
|
291
|
-
* // articles.objects is reactive
|
|
292
|
-
* // articles.loading indicates fetch status
|
|
293
|
-
* // articles.refresh() to manually re-fetch
|
|
294
|
-
* // articles.close() to stop listening
|
|
295
|
-
*/
|
|
296
|
-
collection(options) {
|
|
297
|
-
return new ReactiveCollectionImpl(this.#space, options);
|
|
298
|
-
}
|
|
299
|
-
// Advanced
|
|
300
|
-
rename(...args) { return this.#space.rename(...args); }
|
|
301
|
-
getData() { return this.#space.getData(); }
|
|
302
|
-
get isReadOnly() { return this.#space.isReadOnly; }
|
|
303
|
-
addUser(...args) { return this.#space.addUser(...args); }
|
|
304
|
-
removeUser(...args) { return this.#space.removeUser(...args); }
|
|
305
|
-
listUsers() { return this.#space.listUsers(); }
|
|
306
|
-
setLinkAccess(...args) { return this.#space.setLinkAccess(...args); }
|
|
307
|
-
get linkAccess() { return this.#space.linkAccess; }
|
|
308
|
-
}
|
|
309
|
-
export function wrapSpace(space) {
|
|
310
|
-
return new ReactiveSpaceImpl(space);
|
|
311
|
-
}
|