@thready-web/dsh-bot-plugin 0.0.0-stage → 0.1.0-beta.0
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/LICENSE +21 -0
- package/README.md +45 -2
- package/client.js +646 -0
- package/dist/cdc.js +73 -0
- package/dist/cli.js +352 -0
- package/dist/context.js +262 -0
- package/dist/cron.js +98 -0
- package/dist/desk-ledger.js +91 -0
- package/dist/desk.js +518 -0
- package/dist/engine.js +733 -0
- package/dist/errors.js +46 -0
- package/dist/fs-safe.js +100 -0
- package/dist/http-plugin.js +33 -0
- package/dist/http.js +593 -0
- package/dist/inbox.js +194 -0
- package/dist/index.js +411 -0
- package/dist/live-diff.js +188 -0
- package/dist/live-snapshot.js +152 -0
- package/dist/provision.js +44 -0
- package/dist/router-plugin.js +14 -0
- package/dist/runtime-registry.js +36 -0
- package/dist/session-files.js +111 -0
- package/dist/session-previews.js +111 -0
- package/dist/store.js +598 -0
- package/dist/tools.js +357 -0
- package/dist/triggers.js +874 -0
- package/dist/work-admit.js +128 -0
- package/dist/work-child.js +73 -0
- package/dist/work-durable.js +53 -0
- package/dist/work-http.js +287 -0
- package/dist/work-ledger.js +217 -0
- package/dist/work-mock-host.js +187 -0
- package/dist/work-mock.js +131 -0
- package/dist/work-tickets.js +1042 -0
- package/dist/work-tools.js +150 -0
- package/dist/work-worker.js +1108 -0
- package/fixtures/mock-llm.mjs +267 -0
- package/package.json +54 -4
- package/public/assets/index-Be82iGwe.css +1 -0
- package/public/assets/index-ByU9a3Lh.js +61 -0
- package/public/index.html +14 -0
package/dist/tools.js
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { toolError, asStoreFailure } from "./errors.js";
|
|
3
|
+
import { syncFactFts, syncMemoryFts, EMPTY_STATE } from "./engine.js";
|
|
4
|
+
const OUTPUT = {
|
|
5
|
+
schema: {
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: { ok: { type: 'boolean' } },
|
|
8
|
+
required: ['ok'],
|
|
9
|
+
},
|
|
10
|
+
render(_args, value) {
|
|
11
|
+
return [{ type: 'text', text: JSON.stringify(value) }];
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @param {import('./engine.js').Engine} engine
|
|
16
|
+
* @param {() => number} [viewRevision]
|
|
17
|
+
*/
|
|
18
|
+
export function toolDefinitions(engine, viewRevision = () => 0) {
|
|
19
|
+
const revision = (hostId) => {
|
|
20
|
+
const injected = viewRevision();
|
|
21
|
+
return injected > 0 ? injected : currentRevision(engine, hostId);
|
|
22
|
+
};
|
|
23
|
+
return [
|
|
24
|
+
tool('foundations_recall', 'Search facts and long-term memories that are still active in this session. Forgotten, superseded, and unconfirmed rows are omitted.', {
|
|
25
|
+
type: 'object',
|
|
26
|
+
properties: {
|
|
27
|
+
query: { type: 'string', description: 'Search text' },
|
|
28
|
+
limit: { type: 'integer', description: 'Default 5, maximum 20' },
|
|
29
|
+
sessionId: { type: 'string', description: 'Ignored. The host binds the session.' },
|
|
30
|
+
},
|
|
31
|
+
required: ['query'],
|
|
32
|
+
}, async (args, hostId) => {
|
|
33
|
+
const limit = Math.min(20, Math.max(1, Number.isInteger(args.limit) ? args.limit : 5));
|
|
34
|
+
if (typeof args.query !== 'string' || args.query.trim() === '')
|
|
35
|
+
return toolError('VALIDATION', 'query is required.');
|
|
36
|
+
const found = engine.recall(hostId, args.query.trim(), limit);
|
|
37
|
+
return ok(revision(hostId), 0, found);
|
|
38
|
+
}),
|
|
39
|
+
tool('foundations_remember', 'Store one fact or long-term memory as active. An idempotency key is required.', {
|
|
40
|
+
type: 'object',
|
|
41
|
+
properties: {
|
|
42
|
+
target: { type: 'string', enum: ['fact', 'memory'] },
|
|
43
|
+
content: { type: 'string' },
|
|
44
|
+
title: { type: 'string' },
|
|
45
|
+
priority: { type: 'integer' },
|
|
46
|
+
sourceEventId: { type: 'string' },
|
|
47
|
+
idempotencyKey: { type: 'string' },
|
|
48
|
+
sessionId: { type: 'string', description: 'Ignored. The host binds the session.' },
|
|
49
|
+
},
|
|
50
|
+
required: ['target', 'content', 'idempotencyKey'],
|
|
51
|
+
}, async (args, hostId) => write(engine, hostId, 'foundations_remember', args, () => revision(hostId), () => {
|
|
52
|
+
if (args.target !== 'fact' && args.target !== 'memory')
|
|
53
|
+
return toolError('VALIDATION', 'target must be fact or memory.');
|
|
54
|
+
if (typeof args.content !== 'string' || args.content.trim() === '')
|
|
55
|
+
return toolError('VALIDATION', 'content is required.');
|
|
56
|
+
const sourceError = engine.checkSource(hostId, args.sourceEventId);
|
|
57
|
+
if (sourceError)
|
|
58
|
+
return sourceError;
|
|
59
|
+
const created = nowIso();
|
|
60
|
+
if (args.target === 'fact') {
|
|
61
|
+
const priority = Number.isInteger(args.priority) ? args.priority : 100;
|
|
62
|
+
const info = engine.store.db.prepare(`
|
|
63
|
+
INSERT INTO facts (
|
|
64
|
+
session_id, kind, content, status, source_event_id, source_type, revision, priority, created_at, updated_at
|
|
65
|
+
) VALUES (?, 'user_fact', ?, 'active', ?, 'explicit_tool', 1, ?, ?, ?)
|
|
66
|
+
`).run(hostId, args.content, args.sourceEventId ?? null, priority, created, created);
|
|
67
|
+
const id = Number(info.lastInsertRowid);
|
|
68
|
+
syncFactFts(engine.store.db, id, args.content, true);
|
|
69
|
+
return ok(revision(hostId), 1, { id, target: 'fact', revision: 1 });
|
|
70
|
+
}
|
|
71
|
+
const info = engine.store.db.prepare(`
|
|
72
|
+
INSERT INTO memories (
|
|
73
|
+
session_id, title, content, status, source_event_id, source_type, revision, created_at, updated_at
|
|
74
|
+
) VALUES (?, ?, ?, 'active', ?, 'explicit_tool', 1, ?, ?)
|
|
75
|
+
`).run(hostId, typeof args.title === 'string' ? args.title : null, args.content, args.sourceEventId ?? null, created, created);
|
|
76
|
+
const id = Number(info.lastInsertRowid);
|
|
77
|
+
syncMemoryFts(engine.store.db, id, typeof args.title === 'string' ? args.title : '', args.content, true);
|
|
78
|
+
return ok(revision(hostId), 1, { id, target: 'memory', revision: 1 });
|
|
79
|
+
})),
|
|
80
|
+
tool('foundations_correct', 'Replace one still-active fact or memory with a new row. expectedRevision is required.', {
|
|
81
|
+
type: 'object',
|
|
82
|
+
properties: {
|
|
83
|
+
target: { type: 'string', enum: ['fact', 'memory'] },
|
|
84
|
+
id: { type: 'integer' },
|
|
85
|
+
content: { type: 'string' },
|
|
86
|
+
title: { type: 'string' },
|
|
87
|
+
expectedRevision: { type: 'integer' },
|
|
88
|
+
idempotencyKey: { type: 'string' },
|
|
89
|
+
sessionId: { type: 'string', description: 'Ignored. The host binds the session.' },
|
|
90
|
+
},
|
|
91
|
+
required: ['target', 'id', 'content', 'expectedRevision', 'idempotencyKey'],
|
|
92
|
+
}, async (args, hostId) => write(engine, hostId, 'foundations_correct', args, () => revision(hostId), () => correct(engine, hostId, args))),
|
|
93
|
+
tool('foundations_forget', 'Mark one fact or memory forgotten and drop it from search. The original log is not deleted.', {
|
|
94
|
+
type: 'object',
|
|
95
|
+
properties: {
|
|
96
|
+
target: { type: 'string', enum: ['fact', 'memory'] },
|
|
97
|
+
id: { type: 'integer' },
|
|
98
|
+
expectedRevision: { type: 'integer' },
|
|
99
|
+
idempotencyKey: { type: 'string' },
|
|
100
|
+
sessionId: { type: 'string', description: 'Ignored. The host binds the session.' },
|
|
101
|
+
},
|
|
102
|
+
required: ['target', 'id', 'expectedRevision', 'idempotencyKey'],
|
|
103
|
+
}, async (args, hostId) => write(engine, hostId, 'foundations_forget', args, () => revision(hostId), () => forget(engine, hostId, args))),
|
|
104
|
+
tool('foundations_state_update', 'Patch the working draft for this session. expectedRevision is required.', {
|
|
105
|
+
type: 'object',
|
|
106
|
+
properties: {
|
|
107
|
+
expectedRevision: { type: 'integer' },
|
|
108
|
+
patch: { type: 'object' },
|
|
109
|
+
idempotencyKey: { type: 'string' },
|
|
110
|
+
sessionId: { type: 'string', description: 'Ignored. The host binds the session.' },
|
|
111
|
+
},
|
|
112
|
+
required: ['expectedRevision', 'patch', 'idempotencyKey'],
|
|
113
|
+
}, async (args, hostId) => write(engine, hostId, 'foundations_state_update', args, () => revision(hostId), () => updateState(engine, hostId, args))),
|
|
114
|
+
tool('foundations_skill_load', 'Read the text of an enabled, non-revoked skill in this session. This does not grant tools.', {
|
|
115
|
+
type: 'object',
|
|
116
|
+
properties: {
|
|
117
|
+
skillId: { type: 'string' },
|
|
118
|
+
sessionId: { type: 'string', description: 'Ignored. The host binds the session.' },
|
|
119
|
+
},
|
|
120
|
+
required: ['skillId'],
|
|
121
|
+
}, async (args, hostId) => {
|
|
122
|
+
if (typeof args.skillId !== 'string')
|
|
123
|
+
return toolError('VALIDATION', 'skillId is invalid.');
|
|
124
|
+
const loaded = engine.loadSkill(hostId, args.skillId);
|
|
125
|
+
if (loaded.ok === false)
|
|
126
|
+
return loaded;
|
|
127
|
+
return {
|
|
128
|
+
ok: true,
|
|
129
|
+
outcome: 'applied',
|
|
130
|
+
viewRevisionFrozen: revision(hostId),
|
|
131
|
+
storeRevision: 0,
|
|
132
|
+
data: loaded.data,
|
|
133
|
+
};
|
|
134
|
+
}),
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @param {string} name
|
|
139
|
+
* @param {string} description
|
|
140
|
+
* @param {Record<string, unknown>} parameters
|
|
141
|
+
* @param {(args: Record<string, unknown>, hostId: string) => Promise<unknown>} run
|
|
142
|
+
*/
|
|
143
|
+
function tool(name, description, parameters, run) {
|
|
144
|
+
return {
|
|
145
|
+
name,
|
|
146
|
+
description,
|
|
147
|
+
parameters,
|
|
148
|
+
output: OUTPUT,
|
|
149
|
+
async execute(args, exec) {
|
|
150
|
+
const hostId = exec?.agent?.id;
|
|
151
|
+
if (typeof hostId !== 'string' || hostId === '')
|
|
152
|
+
return toolError('UNAVAILABLE', 'The host did not bind a sessionId.');
|
|
153
|
+
try {
|
|
154
|
+
return publish(await run(args ?? {}, hostId));
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
if (error && typeof error === 'object' && 'code' in error && error.code === 'BUSY') {
|
|
158
|
+
return toolError('BUSY', 'The write lock was not acquired, so nothing was written.');
|
|
159
|
+
}
|
|
160
|
+
return asStoreFailure(error);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* @param {import('./engine.js').Engine} engine
|
|
167
|
+
* @param {string} hostId
|
|
168
|
+
* @param {string} name
|
|
169
|
+
* @param {Record<string, unknown>} args
|
|
170
|
+
* @param {() => number} viewRevision
|
|
171
|
+
* @param {() => Record<string, unknown>} apply
|
|
172
|
+
*/
|
|
173
|
+
async function write(engine, hostId, name, args, viewRevision, apply) {
|
|
174
|
+
const binding = engine.ensureSession(hostId);
|
|
175
|
+
if (binding.status === 'error')
|
|
176
|
+
return toolError('UNAVAILABLE', `Binding is ${binding.error_code ?? 'error'}.`);
|
|
177
|
+
if (typeof args.idempotencyKey !== 'string' || args.idempotencyKey.trim() === '') {
|
|
178
|
+
return toolError('VALIDATION', 'idempotencyKey is required.');
|
|
179
|
+
}
|
|
180
|
+
const payloadHash = createHash('sha256').update(stable(args)).digest('hex');
|
|
181
|
+
const result = await engine.store.write(hostId, () => (engine.mutate(hostId, args.idempotencyKey, payloadHash, name, args, apply, viewRevision())));
|
|
182
|
+
if (result.ok === true && result.outcome === 'applied') {
|
|
183
|
+
const exported = await engine.exportOne({ id: result.mutationId, session_id: hostId, attempts: 0 });
|
|
184
|
+
const final = {
|
|
185
|
+
...result,
|
|
186
|
+
export: exported.ok ? 'done' : 'failed',
|
|
187
|
+
...(exported.ok ? {} : { exportError: exported.error }),
|
|
188
|
+
};
|
|
189
|
+
engine.store.db.prepare('UPDATE mutations SET result_json = ? WHERE id = ?').run(JSON.stringify(final), result.mutationId);
|
|
190
|
+
return final;
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* @param {Record<string, unknown>} result
|
|
196
|
+
*/
|
|
197
|
+
function publish(result) {
|
|
198
|
+
if (result.ok === false)
|
|
199
|
+
return result;
|
|
200
|
+
return {
|
|
201
|
+
ok: true,
|
|
202
|
+
outcome: result.outcome ?? 'applied',
|
|
203
|
+
viewRevisionFrozen: result.viewRevisionFrozen ?? result.viewRevision ?? 0,
|
|
204
|
+
storeRevision: result.storeRevision ?? 0,
|
|
205
|
+
data: result.data,
|
|
206
|
+
...(result.export ? { export: result.export } : {}),
|
|
207
|
+
...(result.exportError ? { exportError: result.exportError } : {}),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* @param {import('./engine.js').Engine} engine
|
|
212
|
+
* @param {string} hostId
|
|
213
|
+
* @param {Record<string, unknown>} args
|
|
214
|
+
*/
|
|
215
|
+
function correct(engine, hostId, args) {
|
|
216
|
+
if ((args.target !== 'fact' && args.target !== 'memory') || typeof args.content !== 'string' || !Number.isInteger(args.id) || !Number.isInteger(args.expectedRevision)) {
|
|
217
|
+
return toolError('VALIDATION', 'correct arguments are incomplete.');
|
|
218
|
+
}
|
|
219
|
+
const table = args.target === 'fact' ? 'facts' : 'memories';
|
|
220
|
+
const row = engine.store.db.prepare(`SELECT * FROM ${table} WHERE id = ? AND session_id = ?`).get(args.id, hostId);
|
|
221
|
+
if (!row || row.status !== 'active')
|
|
222
|
+
return toolError('NOT_FOUND', 'No still-active row was found.');
|
|
223
|
+
if (row.revision !== args.expectedRevision) {
|
|
224
|
+
return toolError('CAS_CONFLICT', 'The revision has changed.', { actualRevision: row.revision });
|
|
225
|
+
}
|
|
226
|
+
const created = nowIso();
|
|
227
|
+
let inserted;
|
|
228
|
+
if (args.target === 'fact') {
|
|
229
|
+
inserted = engine.store.db.prepare(`
|
|
230
|
+
INSERT INTO facts (
|
|
231
|
+
session_id, kind, content, status, source_type, supersedes, revision, priority, created_at, updated_at
|
|
232
|
+
) VALUES (?, 'user_fact', ?, 'active', 'explicit_tool', ?, 1, ?, ?, ?)
|
|
233
|
+
`).run(hostId, args.content, row.id, row.priority, created, created);
|
|
234
|
+
engine.store.db.prepare(`UPDATE facts SET status = 'superseded', revision = ?, updated_at = ? WHERE id = ?`).run(row.revision + 1, created, row.id);
|
|
235
|
+
syncFactFts(engine.store.db, row.id, row.content, false);
|
|
236
|
+
syncFactFts(engine.store.db, Number(inserted.lastInsertRowid), args.content, true);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
const title = typeof args.title === 'string' ? args.title : row.title;
|
|
240
|
+
inserted = engine.store.db.prepare(`
|
|
241
|
+
INSERT INTO memories (
|
|
242
|
+
session_id, title, content, status, source_type, supersedes, revision, created_at, updated_at
|
|
243
|
+
) VALUES (?, ?, ?, 'active', 'explicit_tool', ?, 1, ?, ?)
|
|
244
|
+
`).run(hostId, title, args.content, row.id, created, created);
|
|
245
|
+
engine.store.db.prepare(`UPDATE memories SET status = 'superseded', revision = ?, updated_at = ? WHERE id = ?`).run(row.revision + 1, created, row.id);
|
|
246
|
+
syncMemoryFts(engine.store.db, row.id, row.title, row.content, false);
|
|
247
|
+
syncMemoryFts(engine.store.db, Number(inserted.lastInsertRowid), title, args.content, true);
|
|
248
|
+
}
|
|
249
|
+
return ok(0, 1, { id: Number(inserted.lastInsertRowid), target: args.target, revision: 1, supersedes: row.id });
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* @param {import('./engine.js').Engine} engine
|
|
253
|
+
* @param {string} hostId
|
|
254
|
+
* @param {Record<string, unknown>} args
|
|
255
|
+
*/
|
|
256
|
+
function forget(engine, hostId, args) {
|
|
257
|
+
if ((args.target !== 'fact' && args.target !== 'memory') || !Number.isInteger(args.id) || !Number.isInteger(args.expectedRevision)) {
|
|
258
|
+
return toolError('VALIDATION', 'forget arguments are incomplete.');
|
|
259
|
+
}
|
|
260
|
+
const table = args.target === 'fact' ? 'facts' : 'memories';
|
|
261
|
+
const row = engine.store.db.prepare(`SELECT * FROM ${table} WHERE id = ? AND session_id = ?`).get(args.id, hostId);
|
|
262
|
+
if (!row || row.status !== 'active')
|
|
263
|
+
return toolError('NOT_FOUND', 'No still-active row was found.');
|
|
264
|
+
if (row.revision !== args.expectedRevision)
|
|
265
|
+
return toolError('CAS_CONFLICT', 'The revision has changed.', { actualRevision: row.revision });
|
|
266
|
+
const updated = nowIso();
|
|
267
|
+
engine.store.db.prepare(`UPDATE ${table} SET status = 'forgotten', revision = ?, updated_at = ? WHERE id = ?`).run(row.revision + 1, updated, row.id);
|
|
268
|
+
if (args.target === 'fact')
|
|
269
|
+
syncFactFts(engine.store.db, row.id, row.content, false);
|
|
270
|
+
else
|
|
271
|
+
syncMemoryFts(engine.store.db, row.id, row.title, row.content, false);
|
|
272
|
+
return ok(0, row.revision + 1, { id: row.id, target: args.target, revision: row.revision + 1, forgotten: true });
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* @param {import('./engine.js').Engine} engine
|
|
276
|
+
* @param {string} hostId
|
|
277
|
+
* @param {Record<string, unknown>} args
|
|
278
|
+
*/
|
|
279
|
+
function updateState(engine, hostId, args) {
|
|
280
|
+
if (!Number.isInteger(args.expectedRevision) || args.patch == null || typeof args.patch !== 'object' || Array.isArray(args.patch)) {
|
|
281
|
+
return toolError('VALIDATION', 'state_update arguments are incomplete.');
|
|
282
|
+
}
|
|
283
|
+
const current = engine.statePayload(hostId);
|
|
284
|
+
if (current.revision !== args.expectedRevision) {
|
|
285
|
+
return toolError('CAS_CONFLICT', 'The working-draft revision has changed.', { actualRevision: current.revision });
|
|
286
|
+
}
|
|
287
|
+
const patch = args.patch;
|
|
288
|
+
const next = {
|
|
289
|
+
currentGoal: current.payload.currentGoal ?? '',
|
|
290
|
+
todos: current.payload.todos ?? [],
|
|
291
|
+
pointers: current.payload.pointers ?? [],
|
|
292
|
+
notes: current.payload.notes ?? '',
|
|
293
|
+
};
|
|
294
|
+
if ('currentGoal' in patch) {
|
|
295
|
+
if (typeof patch.currentGoal !== 'string')
|
|
296
|
+
return toolError('VALIDATION', 'currentGoal must be a string.');
|
|
297
|
+
next.currentGoal = patch.currentGoal;
|
|
298
|
+
}
|
|
299
|
+
if ('notes' in patch) {
|
|
300
|
+
if (typeof patch.notes !== 'string')
|
|
301
|
+
return toolError('VALIDATION', 'notes must be a string.');
|
|
302
|
+
next.notes = patch.notes;
|
|
303
|
+
}
|
|
304
|
+
if ('todos' in patch) {
|
|
305
|
+
if (!Array.isArray(patch.todos))
|
|
306
|
+
return toolError('VALIDATION', 'todos must be an array.');
|
|
307
|
+
next.todos = patch.todos;
|
|
308
|
+
}
|
|
309
|
+
if ('pointers' in patch) {
|
|
310
|
+
if (!Array.isArray(patch.pointers))
|
|
311
|
+
return toolError('VALIDATION', 'pointers must be an array.');
|
|
312
|
+
next.pointers = patch.pointers;
|
|
313
|
+
}
|
|
314
|
+
const revision = current.revision + 1;
|
|
315
|
+
const updated = nowIso();
|
|
316
|
+
if (current.revision === 0) {
|
|
317
|
+
engine.store.db.prepare(`
|
|
318
|
+
INSERT INTO working_state (session_id, revision, payload_json, updated_at) VALUES (?, ?, ?, ?)
|
|
319
|
+
`).run(hostId, revision, JSON.stringify(next), updated);
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
engine.store.db.prepare(`
|
|
323
|
+
UPDATE working_state SET revision = ?, payload_json = ?, updated_at = ? WHERE session_id = ?
|
|
324
|
+
`).run(revision, JSON.stringify(next), updated, hostId);
|
|
325
|
+
}
|
|
326
|
+
return ok(0, revision, { revision, payload: next });
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* @param {number} viewRevision
|
|
330
|
+
* @param {number} storeRevision
|
|
331
|
+
* @param {unknown} data
|
|
332
|
+
*/
|
|
333
|
+
function ok(viewRevision, storeRevision, data) {
|
|
334
|
+
return { ok: true, viewRevision, storeRevision, data };
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* @param {unknown} value
|
|
338
|
+
*/
|
|
339
|
+
function stable(value) {
|
|
340
|
+
if (Array.isArray(value))
|
|
341
|
+
return `[${value.map(item => stable(item)).join(',')}]`;
|
|
342
|
+
if (value && typeof value === 'object') {
|
|
343
|
+
return `{${Object.keys(value).sort().map(key => `${JSON.stringify(key)}:${stable(value[key])}`).join(',')}}`;
|
|
344
|
+
}
|
|
345
|
+
return JSON.stringify(value);
|
|
346
|
+
}
|
|
347
|
+
function nowIso() {
|
|
348
|
+
return new Date().toISOString();
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* @param {import('./engine.js').Engine} engine
|
|
352
|
+
* @param {string} sessionId
|
|
353
|
+
*/
|
|
354
|
+
function currentRevision(engine, sessionId) {
|
|
355
|
+
return engine.currentView(sessionId)?.revision ?? engine.binding(sessionId)?.last_view_revision ?? 0;
|
|
356
|
+
}
|
|
357
|
+
export { EMPTY_STATE };
|