@xpert-ai/plugin-sdk 3.16.1 → 3.17.1
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/CHANGELOG.md +21 -0
- package/_extends.cjs.js +14 -0
- package/_extends.esm.js +12 -0
- package/collaboration-client.cjs.js +392 -8
- package/collaboration-client.esm.js +389 -1
- package/index.cjs.js +500 -285
- package/index.esm.js +444 -247
- package/model-provider-http-client.cjs.default.js +1 -0
- package/model-provider-http-client.cjs.js +118 -0
- package/model-provider-http-client.cjs.mjs +2 -0
- package/model-provider-http-client.d.ts +1 -0
- package/model-provider-http-client.esm.js +115 -0
- package/model-provider-toolset.cjs.default.js +1 -0
- package/model-provider-toolset.cjs.js +12 -0
- package/model-provider-toolset.cjs.mjs +2 -0
- package/model-provider-toolset.d.ts +1 -0
- package/model-provider-toolset.esm.js +6 -0
- package/model-provider.cjs.js +348 -0
- package/model-provider.esm.js +328 -0
- package/package.json +14 -2
- package/src/index.d.ts +1 -0
- package/src/lib/agent/middleware/capabilities/assistant-task.d.ts +3 -0
- package/src/lib/agent/middleware/index.d.ts +1 -0
- package/src/lib/agent/middleware/model-output-validation-error.d.ts +27 -0
- package/src/lib/agent/middleware/runtime.d.ts +43 -4
- package/src/lib/ai-model/abstract-provider.d.ts +2 -2
- package/src/lib/ai-model/ai-model-provider.interface.d.ts +3 -3
- package/src/lib/ai-model/ai-model.d.ts +4 -1
- package/src/lib/ai-model/index.d.ts +2 -0
- package/src/lib/ai-model/llm.d.ts +49 -3
- package/src/lib/ai-model/managed-aigc-job.d.ts +37 -0
- package/src/lib/ai-model/model-provider-http-client.d.ts +51 -0
- package/src/lib/ai-model/pricing.d.ts +13 -1
- package/src/lib/ai-model/types/aigc.d.ts +39 -0
- package/src/lib/ai-model/types/index.d.ts +1 -0
- package/src/lib/ai-model/types/model.d.ts +11 -4
- package/src/lib/core/runtime-capability.d.ts +2 -0
- package/src/lib/evolution/index.d.ts +4 -0
- package/src/lib/evolution/provider.decorator.d.ts +2 -0
- package/src/lib/evolution/provider.registry.d.ts +7 -0
- package/src/lib/evolution/runtime-capability.d.ts +3 -0
- package/src/lib/managed-queue/index.d.ts +3 -1
- package/src/lib/runtime/capabilities/knowledgebase-documents.d.ts +59 -1
- package/src/lib/runtime/capabilities/knowledgebase.d.ts +95 -3
- package/src/lib/runtime/capabilities/workspace-files.d.ts +5 -0
- package/src/lib/toolset/builtin.d.ts +28 -0
- package/src/lib/toolset/index.d.ts +1 -0
- package/src/lib/toolset/model-provider.d.ts +31 -0
- package/src/lib/vectorstore/strategy.interface.d.ts +3 -0
- package/src/model-provider-http-client.d.ts +1 -0
- package/src/model-provider-toolset.d.ts +1 -0
- package/collaboration-client.cjs2.js +0 -406
- package/collaboration-client.esm2.js +0 -398
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @xpert-ai/plugin-sdk
|
|
2
2
|
|
|
3
|
+
## 3.17.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 612baea: Resolve model parameter defaults consistently across configuration UIs and runtime model creation, and expose provider parameter rules through the plugin SDK.
|
|
8
|
+
- Updated dependencies [612baea]
|
|
9
|
+
- @xpert-ai/contracts@3.17.1
|
|
10
|
+
|
|
11
|
+
## 3.17.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- 747732e: v3.17
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- e44e5bc: Add shared IMAGE and VIDEO model clients, Managed Queue checkpoints for asynchronous AIGC jobs, host-owned model provider resolution, authoritative model usage reporting, and versioned token/generation/second usage accounting for model plugins.
|
|
20
|
+
- Updated dependencies [747732e]
|
|
21
|
+
- Updated dependencies [e44e5bc]
|
|
22
|
+
- @xpert-ai/contracts@3.17.0
|
|
23
|
+
|
|
3
24
|
## 3.16.1
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/_extends.cjs.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _extends() {
|
|
4
|
+
_extends = Object.assign || function assign(target) {
|
|
5
|
+
for(var i = 1; i < arguments.length; i++){
|
|
6
|
+
var source = arguments[i];
|
|
7
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
8
|
+
}
|
|
9
|
+
return target;
|
|
10
|
+
};
|
|
11
|
+
return _extends.apply(this, arguments);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports._extends = _extends;
|
package/_extends.esm.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function _extends() {
|
|
2
|
+
_extends = Object.assign || function assign(target) {
|
|
3
|
+
for(var i = 1; i < arguments.length; i++){
|
|
4
|
+
var source = arguments[i];
|
|
5
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
6
|
+
}
|
|
7
|
+
return target;
|
|
8
|
+
};
|
|
9
|
+
return _extends.apply(this, arguments);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { _extends as _ };
|
|
@@ -1,12 +1,396 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _extends = require('./_extends.cjs.js');
|
|
4
4
|
|
|
5
|
+
function createSocketIoTransportAdapter(socket) {
|
|
6
|
+
return {
|
|
7
|
+
get connected () {
|
|
8
|
+
return socket.connected;
|
|
9
|
+
},
|
|
10
|
+
get clientId () {
|
|
11
|
+
var _socket_id;
|
|
12
|
+
return (_socket_id = socket.id) != null ? _socket_id : null;
|
|
13
|
+
},
|
|
14
|
+
connect: ()=>{
|
|
15
|
+
socket.connect();
|
|
16
|
+
},
|
|
17
|
+
disconnect: ()=>{
|
|
18
|
+
socket.disconnect();
|
|
19
|
+
},
|
|
20
|
+
emit: (event, payload = {})=>{
|
|
21
|
+
socket.emit(event, payload);
|
|
22
|
+
},
|
|
23
|
+
on: (event, handler)=>{
|
|
24
|
+
socket.on(event, handler);
|
|
25
|
+
return ()=>{
|
|
26
|
+
socket.off(event, handler);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Wrap a caller-owned `Y.Doc` without passing it across the runtime capability boundary. */ function createYjsDocumentAdapter(document, yjs) {
|
|
32
|
+
return {
|
|
33
|
+
applyUpdate: (update, origin)=>yjs.applyUpdate(document, update, origin),
|
|
34
|
+
encodeStateVector: ()=>yjs.encodeStateVector(document),
|
|
35
|
+
mergeUpdates: (updates)=>yjs.mergeUpdates(updates),
|
|
36
|
+
onUpdate: (handler)=>{
|
|
37
|
+
document.on('update', handler);
|
|
38
|
+
return ()=>document.off('update', handler);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Keep per-client sessions for cursors while exposing one collaborator per stable actor identity.
|
|
44
|
+
* This prevents a second tab owned by the same user from either duplicating or hiding that user.
|
|
45
|
+
*/ function createCollaborationPresenceStore(options = {}) {
|
|
46
|
+
let selfClientId = null;
|
|
47
|
+
let sessions = new Map();
|
|
48
|
+
const readSnapshot = ()=>{
|
|
49
|
+
const activeSessions = Array.from(sessions.values()).sort((left, right)=>right.updatedAt - left.updatedAt);
|
|
50
|
+
const remoteSessions = activeSessions.filter((item)=>item.clientId !== selfClientId);
|
|
51
|
+
const actors = new Map();
|
|
52
|
+
for (const item of activeSessions)if (!actors.has(item.presenceId)) actors.set(item.presenceId, item);
|
|
53
|
+
if (options.includeSelf !== false && options.selfActor) {
|
|
54
|
+
const existing = activeSessions.find((item)=>{
|
|
55
|
+
var _options_selfActor;
|
|
56
|
+
return item.clientId === selfClientId || item.presenceId === ((_options_selfActor = options.selfActor) == null ? void 0 : _options_selfActor.presenceId);
|
|
57
|
+
});
|
|
58
|
+
actors.set(options.selfActor.presenceId, existing != null ? existing : actorPresence(options.selfActor, selfClientId));
|
|
59
|
+
}
|
|
60
|
+
const collaborators = Array.from(actors.values()).sort((left, right)=>{
|
|
61
|
+
var _options_selfActor, _options_selfActor1;
|
|
62
|
+
const leftSelf = left.presenceId === ((_options_selfActor = options.selfActor) == null ? void 0 : _options_selfActor.presenceId) ? 1 : 0;
|
|
63
|
+
const rightSelf = right.presenceId === ((_options_selfActor1 = options.selfActor) == null ? void 0 : _options_selfActor1.presenceId) ? 1 : 0;
|
|
64
|
+
return rightSelf - leftSelf || right.updatedAt - left.updatedAt;
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
selfClientId,
|
|
68
|
+
sessions: activeSessions,
|
|
69
|
+
remoteSessions,
|
|
70
|
+
collaborators
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
const publish = ()=>options.onChange == null ? void 0 : options.onChange.call(options, readSnapshot());
|
|
74
|
+
return {
|
|
75
|
+
setSelfClientId: (clientId)=>{
|
|
76
|
+
selfClientId = clientId;
|
|
77
|
+
publish();
|
|
78
|
+
},
|
|
79
|
+
replace: (items, clientId = selfClientId)=>{
|
|
80
|
+
selfClientId = clientId;
|
|
81
|
+
sessions = new Map(items.map((item)=>[
|
|
82
|
+
item.clientId,
|
|
83
|
+
item
|
|
84
|
+
]));
|
|
85
|
+
publish();
|
|
86
|
+
},
|
|
87
|
+
upsert: (item)=>{
|
|
88
|
+
sessions.set(item.clientId, item);
|
|
89
|
+
publish();
|
|
90
|
+
},
|
|
91
|
+
remove: (clientId)=>{
|
|
92
|
+
if (sessions.delete(clientId)) publish();
|
|
93
|
+
},
|
|
94
|
+
clear: ()=>{
|
|
95
|
+
sessions.clear();
|
|
96
|
+
selfClientId = null;
|
|
97
|
+
publish();
|
|
98
|
+
},
|
|
99
|
+
snapshot: readSnapshot
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Create a collaboration client with update batching, state-vector repair, presence heartbeat,
|
|
104
|
+
* and reconnect synchronization. The caller retains ownership of the document and transport.
|
|
105
|
+
*/ function createCollaborationClient(options) {
|
|
106
|
+
const remoteOrigin = Object.freeze({
|
|
107
|
+
kind: 'platform.collaboration.remote'
|
|
108
|
+
});
|
|
109
|
+
const batchMs = positiveInteger(options.batchMs, 40);
|
|
110
|
+
const syncIntervalMs = positiveInteger(options.syncIntervalMs, 2000);
|
|
111
|
+
const presenceHeartbeatMs = positiveInteger(options.presenceHeartbeatMs, 5000);
|
|
112
|
+
const presenceStaleMs = positiveInteger(options.presenceStaleMs, 15000);
|
|
113
|
+
var _options_initialPresence;
|
|
114
|
+
let presence = _extends._extends({}, (_options_initialPresence = options.initialPresence) != null ? _options_initialPresence : {});
|
|
115
|
+
let pending = [];
|
|
116
|
+
let flushTimer;
|
|
117
|
+
let syncTimer;
|
|
118
|
+
let presenceTimer;
|
|
119
|
+
let presenceCleanupTimer;
|
|
120
|
+
var _options_transport_clientId;
|
|
121
|
+
let selfClientId = (_options_transport_clientId = options.transport.clientId) != null ? _options_transport_clientId : null;
|
|
122
|
+
let started = false;
|
|
123
|
+
const cleanups = [];
|
|
124
|
+
const presenceSeenAt = new Map();
|
|
125
|
+
const reportError = (error)=>options.onError == null ? void 0 : options.onError.call(options, error instanceof Error ? error : new Error(String(error)));
|
|
126
|
+
const emitPresence = ()=>options.transport.emit('presence', _extends._extends({}, presence));
|
|
127
|
+
// Merge the short burst of local Yjs transactions into one network update.
|
|
128
|
+
const flush = ()=>{
|
|
129
|
+
if (flushTimer) clearTimeout(flushTimer);
|
|
130
|
+
flushTimer = undefined;
|
|
131
|
+
if (!pending.length || !options.transport.connected) return;
|
|
132
|
+
const updates = pending;
|
|
133
|
+
pending = [];
|
|
134
|
+
options.transport.emit('update', {
|
|
135
|
+
updateBase64: bytesToBase64(options.document.mergeUpdates(updates)),
|
|
136
|
+
origin: 'plugin-client'
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
// A state vector lets the server return only bytes missing from this client.
|
|
140
|
+
const requestSync = ()=>{
|
|
141
|
+
if (!options.transport.connected) return;
|
|
142
|
+
options.transport.emit('sync-request', {
|
|
143
|
+
stateVectorBase64: bytesToBase64(options.document.encodeStateVector())
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
// Mark server updates with `remoteOrigin` so the document observer does not send them back.
|
|
147
|
+
const applyRemote = (payload)=>{
|
|
148
|
+
const encoded = stringValue(payload['updateBase64']);
|
|
149
|
+
if (!encoded) return;
|
|
150
|
+
try {
|
|
151
|
+
options.document.applyUpdate(base64ToBytes(encoded), remoteOrigin);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
reportError(error);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
// Register listeners once, then start repair and presence heartbeats before opening the socket.
|
|
157
|
+
const connect = ()=>{
|
|
158
|
+
if (started) return;
|
|
159
|
+
started = true;
|
|
160
|
+
options.onConnectionChange == null ? void 0 : options.onConnectionChange.call(options, 'connecting');
|
|
161
|
+
cleanups.push(options.document.onUpdate((update, origin)=>{
|
|
162
|
+
if (origin === remoteOrigin) return;
|
|
163
|
+
pending.push(update);
|
|
164
|
+
if (!flushTimer) flushTimer = setTimeout(flush, batchMs);
|
|
165
|
+
}));
|
|
166
|
+
cleanups.push(options.transport.on('connect', ()=>{
|
|
167
|
+
var _options_transport_clientId;
|
|
168
|
+
selfClientId = (_options_transport_clientId = options.transport.clientId) != null ? _options_transport_clientId : selfClientId;
|
|
169
|
+
options.onConnectionChange == null ? void 0 : options.onConnectionChange.call(options, 'connected');
|
|
170
|
+
requestSync();
|
|
171
|
+
emitPresence();
|
|
172
|
+
}));
|
|
173
|
+
cleanups.push(options.transport.on('disconnect', ()=>options.onConnectionChange == null ? void 0 : options.onConnectionChange.call(options, 'disconnected')));
|
|
174
|
+
cleanups.push(options.transport.on('sync', applyRemote));
|
|
175
|
+
cleanups.push(options.transport.on('update', applyRemote));
|
|
176
|
+
cleanups.push(options.transport.on('update-ack', (payload)=>{
|
|
177
|
+
const ack = parseAck(payload);
|
|
178
|
+
if (ack) options.onAck == null ? void 0 : options.onAck.call(options, ack);
|
|
179
|
+
}));
|
|
180
|
+
cleanups.push(options.transport.on('presence', (payload)=>{
|
|
181
|
+
const item = parsePresence(payload);
|
|
182
|
+
if (item) {
|
|
183
|
+
presenceSeenAt.set(item.clientId, Date.now());
|
|
184
|
+
options.onPresence == null ? void 0 : options.onPresence.call(options, item);
|
|
185
|
+
}
|
|
186
|
+
}));
|
|
187
|
+
cleanups.push(options.transport.on('presence-snapshot', (payload)=>{
|
|
188
|
+
const rawItems = payload['items'];
|
|
189
|
+
const items = Array.isArray(rawItems) ? rawItems.map(parsePresence).filter(isPresence) : [];
|
|
190
|
+
var _stringValue, _ref;
|
|
191
|
+
selfClientId = (_ref = (_stringValue = stringValue(payload['selfClientId'])) != null ? _stringValue : options.transport.clientId) != null ? _ref : selfClientId;
|
|
192
|
+
presenceSeenAt.clear();
|
|
193
|
+
for (const item of items)presenceSeenAt.set(item.clientId, Date.now());
|
|
194
|
+
options.onPresenceSnapshot == null ? void 0 : options.onPresenceSnapshot.call(options, items, {
|
|
195
|
+
selfClientId
|
|
196
|
+
});
|
|
197
|
+
}));
|
|
198
|
+
cleanups.push(options.transport.on('presence-remove', (payload)=>{
|
|
199
|
+
const clientId = stringValue(payload['clientId']);
|
|
200
|
+
if (clientId) {
|
|
201
|
+
presenceSeenAt.delete(clientId);
|
|
202
|
+
options.onPresenceRemove == null ? void 0 : options.onPresenceRemove.call(options, clientId);
|
|
203
|
+
}
|
|
204
|
+
}));
|
|
205
|
+
cleanups.push(options.transport.on('error', (payload)=>{
|
|
206
|
+
var _stringValue;
|
|
207
|
+
return reportError((_stringValue = stringValue(payload['message'])) != null ? _stringValue : 'Collaboration failed.');
|
|
208
|
+
}));
|
|
209
|
+
syncTimer = setInterval(requestSync, syncIntervalMs);
|
|
210
|
+
presenceTimer = setInterval(emitPresence, presenceHeartbeatMs);
|
|
211
|
+
presenceCleanupTimer = setInterval(()=>{
|
|
212
|
+
const cutoff = Date.now() - presenceStaleMs;
|
|
213
|
+
for (const [clientId, seenAt] of presenceSeenAt){
|
|
214
|
+
if (clientId === selfClientId || seenAt >= cutoff) continue;
|
|
215
|
+
presenceSeenAt.delete(clientId);
|
|
216
|
+
options.onPresenceRemove == null ? void 0 : options.onPresenceRemove.call(options, clientId);
|
|
217
|
+
}
|
|
218
|
+
}, Math.min(5000, Math.max(1000, Math.floor(presenceStaleMs / 3))));
|
|
219
|
+
options.transport.connect();
|
|
220
|
+
};
|
|
221
|
+
// Flush best-effort pending state and release all timers/listeners owned by this client.
|
|
222
|
+
const disconnect = ()=>{
|
|
223
|
+
var _cleanups_pop;
|
|
224
|
+
if (!started) return;
|
|
225
|
+
flush();
|
|
226
|
+
started = false;
|
|
227
|
+
if (flushTimer) clearTimeout(flushTimer);
|
|
228
|
+
if (syncTimer) clearInterval(syncTimer);
|
|
229
|
+
if (presenceTimer) clearInterval(presenceTimer);
|
|
230
|
+
if (presenceCleanupTimer) clearInterval(presenceCleanupTimer);
|
|
231
|
+
flushTimer = undefined;
|
|
232
|
+
syncTimer = undefined;
|
|
233
|
+
presenceTimer = undefined;
|
|
234
|
+
presenceCleanupTimer = undefined;
|
|
235
|
+
presenceSeenAt.clear();
|
|
236
|
+
while(cleanups.length)(_cleanups_pop = cleanups.pop()) == null ? void 0 : _cleanups_pop();
|
|
237
|
+
options.transport.disconnect();
|
|
238
|
+
options.onConnectionChange == null ? void 0 : options.onConnectionChange.call(options, 'disconnected');
|
|
239
|
+
};
|
|
240
|
+
return {
|
|
241
|
+
get selfClientId () {
|
|
242
|
+
return selfClientId;
|
|
243
|
+
},
|
|
244
|
+
remoteOrigin,
|
|
245
|
+
connect,
|
|
246
|
+
disconnect,
|
|
247
|
+
flush,
|
|
248
|
+
requestSync,
|
|
249
|
+
setPresence: (patch)=>{
|
|
250
|
+
presence = _extends._extends({}, presence, patch);
|
|
251
|
+
if (options.transport.connected) emitPresence();
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function actorPresence(actor, clientId) {
|
|
256
|
+
return _extends._extends({}, actor, {
|
|
257
|
+
clientId: clientId != null ? clientId : `self:${actor.presenceId}`,
|
|
258
|
+
pageId: null,
|
|
259
|
+
pointer: null,
|
|
260
|
+
focus: null,
|
|
261
|
+
selection: null,
|
|
262
|
+
viewport: null,
|
|
263
|
+
mode: null,
|
|
264
|
+
status: null,
|
|
265
|
+
toolName: null,
|
|
266
|
+
operationLabel: null,
|
|
267
|
+
updatedAt: Date.now()
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
/** Encode bytes in browsers without Node.js `Buffer`; chunks avoid argument-size limits. */ function bytesToBase64(bytes) {
|
|
271
|
+
let binary = '';
|
|
272
|
+
const chunkSize = 0x8000;
|
|
273
|
+
for(let offset = 0; offset < bytes.length; offset += chunkSize){
|
|
274
|
+
binary += String.fromCharCode(...bytes.subarray(offset, Math.min(offset + chunkSize, bytes.length)));
|
|
275
|
+
}
|
|
276
|
+
return globalThis.btoa(binary);
|
|
277
|
+
}
|
|
278
|
+
/** Decode base64 in browsers without requiring Node.js polyfills. */ function base64ToBytes(value) {
|
|
279
|
+
const binary = globalThis.atob(value);
|
|
280
|
+
const bytes = new Uint8Array(binary.length);
|
|
281
|
+
for(let index = 0; index < binary.length; index += 1)bytes[index] = binary.charCodeAt(index);
|
|
282
|
+
return bytes;
|
|
283
|
+
}
|
|
284
|
+
function parseAck(payload) {
|
|
285
|
+
const documentId = stringValue(payload['documentId']);
|
|
286
|
+
const stateVectorBase64 = stringValue(payload['stateVectorBase64']);
|
|
287
|
+
const sequenceNumber = payload['sequenceNumber'];
|
|
288
|
+
if (!documentId || !stateVectorBase64 || typeof sequenceNumber !== 'number') return null;
|
|
289
|
+
const materializationStatus = payload['materializationStatus'];
|
|
290
|
+
if (materializationStatus !== 'ready' && materializationStatus !== 'pending' && materializationStatus !== 'failed') return null;
|
|
291
|
+
return {
|
|
292
|
+
documentId,
|
|
293
|
+
duplicate: payload['duplicate'] === true,
|
|
294
|
+
sequenceNumber,
|
|
295
|
+
updateId: stringValue(payload['updateId']),
|
|
296
|
+
stateVectorBase64,
|
|
297
|
+
materializationStatus
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
function parsePresence(value) {
|
|
301
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
302
|
+
const item = value;
|
|
303
|
+
const clientId = stringValue(item['clientId']);
|
|
304
|
+
const presenceId = stringValue(item['presenceId']);
|
|
305
|
+
const displayName = stringValue(item['displayName']);
|
|
306
|
+
const color = stringValue(item['color']);
|
|
307
|
+
const actorType = item['actorType'];
|
|
308
|
+
if (!clientId || !presenceId || !displayName || !color || actorType !== 'user' && actorType !== 'agent' && actorType !== 'system') return null;
|
|
309
|
+
return {
|
|
310
|
+
clientId,
|
|
311
|
+
presenceId,
|
|
312
|
+
displayName,
|
|
313
|
+
color,
|
|
314
|
+
actorType,
|
|
315
|
+
avatarUrl: nullableString(item['avatarUrl']),
|
|
316
|
+
pageId: nullableString(item['pageId']),
|
|
317
|
+
pointer: parsePointer(item['pointer']),
|
|
318
|
+
focus: parseFocus(item['focus']),
|
|
319
|
+
selection: parseSelection(item['selection']),
|
|
320
|
+
viewport: parseViewport(item['viewport']),
|
|
321
|
+
mode: nullableString(item['mode']),
|
|
322
|
+
status: actorStatus(item['status']),
|
|
323
|
+
toolName: nullableString(item['toolName']),
|
|
324
|
+
operationLabel: nullableString(item['operationLabel']),
|
|
325
|
+
updatedAt: typeof item['updatedAt'] === 'number' ? item['updatedAt'] : Date.now()
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function parsePointer(value) {
|
|
329
|
+
const item = recordValue(value);
|
|
330
|
+
if (!item || typeof item['x'] !== 'number' || typeof item['y'] !== 'number') return null;
|
|
331
|
+
return {
|
|
332
|
+
pageId: nullableString(item['pageId']),
|
|
333
|
+
x: item['x'],
|
|
334
|
+
y: item['y'],
|
|
335
|
+
visible: item['visible'] !== false
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function parseFocus(value) {
|
|
339
|
+
const item = recordValue(value);
|
|
340
|
+
const kind = item && stringValue(item['kind']);
|
|
341
|
+
if (!item || !kind) return null;
|
|
342
|
+
return {
|
|
343
|
+
kind,
|
|
344
|
+
key: nullableString(item['key']),
|
|
345
|
+
pageId: nullableString(item['pageId']),
|
|
346
|
+
elementId: nullableString(item['elementId']),
|
|
347
|
+
fieldKey: nullableString(item['fieldKey'])
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function parseSelection(value) {
|
|
351
|
+
const item = recordValue(value);
|
|
352
|
+
const kind = item == null ? void 0 : item['kind'];
|
|
353
|
+
if (!item || kind !== 'text' && kind !== 'elements') return null;
|
|
354
|
+
return {
|
|
355
|
+
kind,
|
|
356
|
+
fieldKey: nullableString(item['fieldKey']),
|
|
357
|
+
elementIds: Array.isArray(item['elementIds']) ? item['elementIds'].filter((entry)=>typeof entry === 'string') : null,
|
|
358
|
+
anchorRelativeBase64: nullableString(item['anchorRelativeBase64']),
|
|
359
|
+
headRelativeBase64: nullableString(item['headRelativeBase64'])
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
function parseViewport(value) {
|
|
363
|
+
const item = recordValue(value);
|
|
364
|
+
if (!item || typeof item['zoom'] !== 'number' || typeof item['width'] !== 'number' || typeof item['height'] !== 'number') return null;
|
|
365
|
+
return {
|
|
366
|
+
zoom: item['zoom'],
|
|
367
|
+
width: item['width'],
|
|
368
|
+
height: item['height']
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function recordValue(value) {
|
|
372
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
373
|
+
}
|
|
374
|
+
function isPresence(value) {
|
|
375
|
+
return value !== null;
|
|
376
|
+
}
|
|
377
|
+
function stringValue(value) {
|
|
378
|
+
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
379
|
+
}
|
|
380
|
+
function nullableString(value) {
|
|
381
|
+
var _stringValue;
|
|
382
|
+
return (_stringValue = stringValue(value)) != null ? _stringValue : null;
|
|
383
|
+
}
|
|
384
|
+
function actorStatus(value) {
|
|
385
|
+
return value === 'thinking' || value === 'editing' || value === 'done' || value === 'failed' ? value : null;
|
|
386
|
+
}
|
|
387
|
+
function positiveInteger(value, fallback) {
|
|
388
|
+
return Number.isFinite(value) && Number(value) > 0 ? Math.trunc(Number(value)) : fallback;
|
|
389
|
+
}
|
|
5
390
|
|
|
6
|
-
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
11
|
-
exports.
|
|
12
|
-
exports.createYjsDocumentAdapter = collaborationClient.createYjsDocumentAdapter;
|
|
391
|
+
exports.base64ToBytes = base64ToBytes;
|
|
392
|
+
exports.bytesToBase64 = bytesToBase64;
|
|
393
|
+
exports.createCollaborationClient = createCollaborationClient;
|
|
394
|
+
exports.createCollaborationPresenceStore = createCollaborationPresenceStore;
|
|
395
|
+
exports.createSocketIoTransportAdapter = createSocketIoTransportAdapter;
|
|
396
|
+
exports.createYjsDocumentAdapter = createYjsDocumentAdapter;
|