@abloatai/humans 0.57.0 → 0.59.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/dist/Ablo.d.ts +8 -18
- package/dist/client.d.ts +6 -19
- package/dist/core.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/local/Database.d.ts +1 -1
- package/dist/local/Model.js +10 -1
- package/dist/local/SyncClient.js +5 -0
- package/dist/local/client/createInternalComponents.d.ts +1 -1
- package/dist/local/client/createInternalComponents.js +1 -1
- package/dist/local/client/{createModelProxy.d.ts → createModelOperations.d.ts} +11 -10
- package/dist/local/client/{createModelProxy.js → createModelOperations.js} +240 -313
- package/dist/local/client/options.d.ts +2 -2
- package/dist/local/client/reactiveEngine.js +34 -45
- package/dist/local/client/resourceTypes.d.ts +3 -3
- package/dist/local/client/resourceTypes.js +1 -1
- package/dist/local/client/schemaConfig.js +1 -0
- package/dist/local/client/wsMutationExecutor.d.ts +4 -4
- package/dist/local/client/wsMutationExecutor.js +3 -5
- package/dist/local/coordination/ClaimLog.d.ts +3 -3
- package/dist/local/coordination/ClaimLog.js +2 -2
- package/dist/local/interfaces/index.d.ts +10 -7
- package/dist/local/mutators/mutateActions.d.ts +3 -2
- package/dist/local/query/types.d.ts +2 -2
- package/dist/local/stores/syncAction.d.ts +1 -1
- package/dist/local/stores/syncAction.js +1 -1
- package/dist/local/sync/BootstrapFetcher.js +4 -4
- package/dist/local/sync/ConnectionManager.d.ts +1 -1
- package/dist/local/sync/ConnectionManager.js +1 -1
- package/dist/local/sync/OnDemandLoader.d.ts +1 -1
- package/dist/local/sync/OnDemandLoader.js +1 -1
- package/dist/local/sync/SyncWebSocket.d.ts +3 -3
- package/dist/local/sync/SyncWebSocket.js +2 -2
- package/dist/local/sync/commitFrames.d.ts +1 -1
- package/dist/local/sync/commitFrames.js +1 -1
- package/dist/local/sync/contextOnChange.d.ts +8 -0
- package/dist/local/sync/contextOnChange.js +65 -0
- package/dist/local/sync/createClaimStream.d.ts +1 -1
- package/dist/local/sync/createClaimStream.js +47 -28
- package/dist/local/sync/credentialLifecycle.d.ts +1 -1
- package/dist/local/sync/credentialLifecycle.js +1 -1
- package/dist/local/sync/participants.d.ts +1 -1
- package/dist/local/sync/schemaDrift.d.ts +15 -1
- package/dist/local/sync/schemaDrift.js +30 -13
- package/dist/local/sync/schemas.d.ts +2 -2
- package/dist/local/sync/schemas.js +1 -1
- package/dist/local/sync/wsFrameHandlers.d.ts +1 -1
- package/dist/local/sync/wsFrameHandlers.js +1 -1
- package/dist/local/transactions/databaseCommitOutbox.d.ts +2 -2
- package/dist/local/transactions/mutations/MutationQueue.d.ts +4 -19
- package/dist/local/transactions/mutations/MutationQueue.js +5 -70
- package/dist/local/transactions/mutations/batchProcessing.d.ts +2 -13
- package/dist/local/transactions/mutations/batchProcessing.js +0 -20
- package/dist/local/transactions/mutations/commitApi.d.ts +2 -3
- package/dist/local/transactions/mutations/commitApi.js +0 -4
- package/dist/local/transactions/mutations/commitLane.d.ts +3 -8
- package/dist/local/transactions/mutations/commitLane.js +0 -11
- package/dist/local/transactions/mutations/commitPayload.d.ts +2 -4
- package/dist/local/transactions/mutations/commitPayload.js +2 -6
- package/dist/local/transactions/mutations/commitTransport.d.ts +3 -4
- package/dist/local/transactions/mutations/commitTransport.js +2 -5
- package/dist/local/transactions/mutations/durableCommitRestore.d.ts +1 -1
- package/dist/local/transactions/mutations/durableCommitRestore.js +1 -4
- package/dist/local/transactions/mutations/durableWriteStore.d.ts +5 -5
- package/dist/local/transactions/mutations/durableWriteStore.js +3 -3
- package/dist/local/transactions/mutations/failurePolicy.d.ts +2 -2
- package/dist/local/transactions/mutations/mutationPersistence.d.ts +1 -1
- package/dist/local/transactions/mutations/pendingDrain.d.ts +2 -2
- package/dist/local/transactions/mutations/replayValidation.d.ts +0 -20
- package/dist/local/transactions/mutations/replayValidation.js +1 -3
- package/dist/local/transactions/persistedTransaction.d.ts +0 -2
- package/dist/plugin.d.ts +2 -2
- package/dist/presenceStream.d.ts +1 -1
- package/dist/react/createAbloReact.d.ts +1 -1
- package/dist/react/useAblo.d.ts +2 -2
- package/dist/react/useAblo.js +1 -1
- package/dist/surface.d.ts +1 -1
- package/dist/surface.js +1 -2
- package/package.json +2 -2
- package/src/Ablo.ts +9 -27
- package/src/client.ts +6 -22
- package/src/core.ts +1 -1
- package/src/local/Database.ts +1 -1
- package/src/local/Model.ts +12 -1
- package/src/local/SyncClient.ts +5 -0
- package/src/local/client/createInternalComponents.ts +2 -2
- package/src/local/client/{createModelProxy.ts → createModelOperations.ts} +292 -367
- package/src/local/client/options.ts +2 -2
- package/src/local/client/reactiveEngine.ts +63 -55
- package/src/local/client/resourceTypes.ts +4 -4
- package/src/local/client/schemaConfig.ts +3 -0
- package/src/local/client/wsMutationExecutor.ts +3 -9
- package/src/local/coordination/ClaimLog.ts +3 -3
- package/src/local/interfaces/index.ts +7 -7
- package/src/local/mutators/mutateActions.ts +3 -2
- package/src/local/query/types.ts +2 -2
- package/src/local/stores/syncAction.ts +1 -1
- package/src/local/sync/BootstrapFetcher.ts +5 -4
- package/src/local/sync/ConnectionManager.ts +1 -1
- package/src/local/sync/OnDemandLoader.ts +1 -1
- package/src/local/sync/SyncWebSocket.ts +3 -3
- package/src/local/sync/commitFrames.ts +1 -2
- package/src/local/sync/contextOnChange.ts +92 -0
- package/src/local/sync/createClaimStream.ts +77 -39
- package/src/local/sync/credentialLifecycle.ts +1 -1
- package/src/local/sync/participants.ts +1 -1
- package/src/local/sync/schemaDrift.ts +32 -16
- package/src/local/sync/schemas.ts +1 -1
- package/src/local/sync/wsFrameHandlers.ts +1 -1
- package/src/local/transactions/databaseCommitOutbox.ts +2 -2
- package/src/local/transactions/mutations/MutationQueue.ts +8 -95
- package/src/local/transactions/mutations/batchProcessing.ts +2 -38
- package/src/local/transactions/mutations/commitApi.ts +3 -7
- package/src/local/transactions/mutations/commitLane.ts +3 -17
- package/src/local/transactions/mutations/commitPayload.ts +3 -11
- package/src/local/transactions/mutations/commitTransport.ts +3 -7
- package/src/local/transactions/mutations/durableCommitRestore.ts +2 -5
- package/src/local/transactions/mutations/durableWriteStore.ts +5 -5
- package/src/local/transactions/mutations/failurePolicy.ts +2 -2
- package/src/local/transactions/mutations/mutationPersistence.ts +1 -1
- package/src/local/transactions/mutations/pendingDrain.ts +2 -2
- package/src/local/transactions/mutations/replayValidation.ts +1 -3
- package/src/local/transactions/persistedTransaction.ts +0 -3
- package/src/plugin.ts +2 -2
- package/src/presenceStream.ts +2 -2
- package/src/react/createAbloReact.ts +1 -1
- package/src/react/useAblo.ts +2 -2
- package/src/surface.ts +2 -3
- package/dist/local/sync/createSnapshot.d.ts +0 -29
- package/dist/local/sync/createSnapshot.js +0 -116
- package/src/local/sync/createSnapshot.ts +0 -160
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Captures a local {@link Snapshot} of a chosen set of entities, along with a
|
|
3
|
-
* watermark, so a caller can detect when that state has gone stale. This is
|
|
4
|
-
* what an LLM caller threads into a prompt: `stamp` flows into later writes as
|
|
5
|
-
* `readAt`, so the server rejects a mutation premised on data that has since
|
|
6
|
-
* changed; `signal` is an `AbortSignal` that fires as soon as any captured
|
|
7
|
-
* entity receives a delta, so a mid-generation invalidation can abort the token
|
|
8
|
-
* stream instead of producing output against stale context.
|
|
9
|
-
*
|
|
10
|
-
* It reads the current entity state from the in-memory pool, reads the engine's
|
|
11
|
-
* current `lastSyncId` as the watermark, and subscribes to delta frames on the
|
|
12
|
-
* existing sync connection — no second connection.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import type { InstanceCache } from '../InstanceCache.js';
|
|
16
|
-
import type { Schema } from '@abloatai/transaction/schema/schema';
|
|
17
|
-
import type { SyncDelta, SyncWebSocket } from './SyncWebSocket.js';
|
|
18
|
-
import type {
|
|
19
|
-
ContextChange,
|
|
20
|
-
Snapshot,
|
|
21
|
-
} from '@abloatai/transaction/types/streams';
|
|
22
|
-
import { AbloValidationError } from '@abloatai/transaction/errors';
|
|
23
|
-
import { modelAsRow } from '../Model.js';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The snapshot result exposes `stamp`, `signal`, and `onChange` at its top
|
|
27
|
-
* level, alongside one bucket per model. If a schema declares a model with one
|
|
28
|
-
* of these names, the two would collide, so snapshot creation throws instead.
|
|
29
|
-
*/
|
|
30
|
-
const RESERVED_SNAPSHOT_KEYS: ReadonlySet<string> = new Set([
|
|
31
|
-
'stamp',
|
|
32
|
-
'signal',
|
|
33
|
-
'onChange',
|
|
34
|
-
]);
|
|
35
|
-
|
|
36
|
-
export interface CreateSnapshotArgs<
|
|
37
|
-
TSchema extends Schema = Schema,
|
|
38
|
-
K extends keyof TSchema['models'] & string = keyof TSchema['models'] & string,
|
|
39
|
-
> {
|
|
40
|
-
pool: InstanceCache;
|
|
41
|
-
/** Live transport for delta subscriptions. May be null if the engine
|
|
42
|
-
* hasn't connected yet — the snapshot still resolves with current
|
|
43
|
-
* pool state, but `signal` won't fire until reconnect. */
|
|
44
|
-
transport: SyncWebSocket | null;
|
|
45
|
-
/** Returns the engine's current `lastSyncId`. Read at snapshot time
|
|
46
|
-
* to stamp the watermark; not re-read after. */
|
|
47
|
-
getLastSyncId: () => number;
|
|
48
|
-
entities: Readonly<Record<K, string | readonly string[]>>;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function createSnapshot<
|
|
52
|
-
TSchema extends Schema,
|
|
53
|
-
K extends keyof TSchema['models'] & string,
|
|
54
|
-
>(args: CreateSnapshotArgs<TSchema, K>): Snapshot<TSchema, K> {
|
|
55
|
-
const { pool, transport, getLastSyncId, entities } = args;
|
|
56
|
-
|
|
57
|
-
// ── Validate keys ────────────────────────────────────────────────
|
|
58
|
-
for (const key of Object.keys(entities)) {
|
|
59
|
-
if (RESERVED_SNAPSHOT_KEYS.has(key)) {
|
|
60
|
-
throw new AbloValidationError(
|
|
61
|
-
`engine.snapshot: model key "${key}" collides with a reserved ` +
|
|
62
|
-
`snapshot field (stamp / signal / onChange). Rename the model ` +
|
|
63
|
-
'in your schema.',
|
|
64
|
-
{ code: 'snapshot_reserved_key' },
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// ── Watermark ────────────────────────────────────────────────────
|
|
70
|
-
const stamp = getLastSyncId();
|
|
71
|
-
|
|
72
|
-
// ── Capture data + watched set ───────────────────────────────────
|
|
73
|
-
const watched = new Set<string>(); // `${type}:${id}`
|
|
74
|
-
const data: Record<string, Record<string, unknown>> = {};
|
|
75
|
-
|
|
76
|
-
for (const [type, idOrIds] of Object.entries(entities)) {
|
|
77
|
-
const ids = Array.isArray(idOrIds)
|
|
78
|
-
? (idOrIds as readonly string[])
|
|
79
|
-
: [idOrIds as string];
|
|
80
|
-
const bucket: Record<string, unknown> = {};
|
|
81
|
-
for (const id of ids) {
|
|
82
|
-
const m = pool.get(id);
|
|
83
|
-
// Only include if the model actually has the requested type —
|
|
84
|
-
// pool keys models globally by id, so `pool.get(id)` could
|
|
85
|
-
// return a different model that happens to share the id (rare,
|
|
86
|
-
// but type guards keep the surface honest).
|
|
87
|
-
if (
|
|
88
|
-
m &&
|
|
89
|
-
typeof (m as { getModelName?: unknown }).getModelName === 'function' &&
|
|
90
|
-
m.getModelName() === type
|
|
91
|
-
) {
|
|
92
|
-
bucket[id] = modelAsRow(m);
|
|
93
|
-
}
|
|
94
|
-
watched.add(`${type}:${id}`);
|
|
95
|
-
}
|
|
96
|
-
data[type] = bucket;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// ── Invalidation wiring ──────────────────────────────────────────
|
|
100
|
-
const listeners = new Set<(change: ContextChange) => void>();
|
|
101
|
-
const controller = new AbortController();
|
|
102
|
-
|
|
103
|
-
const fireChange = (change: ContextChange) => {
|
|
104
|
-
if (!controller.signal.aborted) {
|
|
105
|
-
controller.abort(
|
|
106
|
-
new Error(
|
|
107
|
-
'snapshot invalidated — underlying entity received a delta',
|
|
108
|
-
),
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
for (const l of listeners) {
|
|
112
|
-
try {
|
|
113
|
-
l(change);
|
|
114
|
-
} catch {
|
|
115
|
-
/* listener errors don't break siblings */
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
let unsubDelta: (() => void) | null = null;
|
|
121
|
-
if (transport) {
|
|
122
|
-
unsubDelta = transport.subscribe('delta', (delta: SyncDelta) => {
|
|
123
|
-
const key = `${delta.modelName}:${delta.modelId}`;
|
|
124
|
-
if (!watched.has(key)) return;
|
|
125
|
-
// Every delta to a captured entity is reported as 'semantic' severity.
|
|
126
|
-
fireChange({
|
|
127
|
-
model: delta.modelName,
|
|
128
|
-
id: delta.modelId,
|
|
129
|
-
severity: 'semantic',
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// ── Build the flat result ────────────────────────────────────────
|
|
135
|
-
const result: Record<string, unknown> = {
|
|
136
|
-
stamp,
|
|
137
|
-
signal: controller.signal,
|
|
138
|
-
onChange: (listener: (change: ContextChange) => void) => {
|
|
139
|
-
listeners.add(listener);
|
|
140
|
-
// The caller unsubscribes its own listener via the returned function.
|
|
141
|
-
// The underlying delta subscription lives for the snapshot's lifetime;
|
|
142
|
-
// there is no explicit dispose because a snapshot is short-lived (one
|
|
143
|
-
// LLM call's worth) and the subscription is cheap.
|
|
144
|
-
return () => {
|
|
145
|
-
listeners.delete(listener);
|
|
146
|
-
// Once the last listener is gone and the abort has fired, drop the
|
|
147
|
-
// delta subscription too — nothing is listening anymore.
|
|
148
|
-
if (listeners.size === 0 && controller.signal.aborted && unsubDelta) {
|
|
149
|
-
unsubDelta();
|
|
150
|
-
unsubDelta = null;
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
for (const [modelName, bucket] of Object.entries(data)) {
|
|
156
|
-
result[modelName] = bucket;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return result as Snapshot<TSchema, K>;
|
|
160
|
-
}
|