@agentshouse/mdruntime 0.1.0-cebcd51f70ed1 → 0.1.0-cedb03eaa48b6
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/AGENTS.md +283 -222
- package/README.md +20 -10
- package/dist/adapter.d.ts +95 -20
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +15 -2
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +70 -0
- package/dist/binary.d.ts +23 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +18 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +113 -37
- package/dist/change-set.d.ts +2 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +49 -16
- package/dist/change.d.ts +15 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +26 -1
- package/dist/chat/acts.d.ts +33 -0
- package/dist/chat/acts.d.ts.map +1 -0
- package/dist/chat/acts.js +36 -0
- package/dist/chat/context.d.ts +3 -0
- package/dist/chat/context.d.ts.map +1 -0
- package/dist/chat/context.js +10 -0
- package/dist/chat/earlier.d.ts +10 -0
- package/dist/chat/earlier.d.ts.map +1 -0
- package/dist/chat/earlier.js +54 -0
- package/dist/chat/input.d.ts +9 -0
- package/dist/chat/input.d.ts.map +1 -0
- package/dist/chat/input.js +99 -0
- package/dist/chat/kit.d.ts +61 -0
- package/dist/chat/kit.d.ts.map +1 -0
- package/dist/chat/kit.js +123 -0
- package/dist/chat/lasting.d.ts +6 -0
- package/dist/chat/lasting.d.ts.map +1 -0
- package/dist/chat/lasting.js +19 -0
- package/dist/chat/list.d.ts +27 -0
- package/dist/chat/list.d.ts.map +1 -0
- package/dist/chat/list.js +99 -0
- package/dist/chat/markdown.d.ts +20 -0
- package/dist/chat/markdown.d.ts.map +1 -0
- package/dist/chat/markdown.js +188 -0
- package/dist/chat/message.d.ts +6 -0
- package/dist/chat/message.d.ts.map +1 -0
- package/dist/chat/message.js +192 -0
- package/dist/chat/messages.d.ts +22 -0
- package/dist/chat/messages.d.ts.map +1 -0
- package/dist/chat/messages.js +155 -0
- package/dist/chat/name.d.ts +6 -0
- package/dist/chat/name.d.ts.map +1 -0
- package/dist/chat/name.js +37 -0
- package/dist/chat/opened.d.ts +11 -0
- package/dist/chat/opened.d.ts.map +1 -0
- package/dist/chat/opened.js +17 -0
- package/dist/chat/overlay.d.ts +31 -0
- package/dist/chat/overlay.d.ts.map +1 -0
- package/dist/chat/overlay.js +97 -0
- package/dist/chat/parts.d.ts +57 -0
- package/dist/chat/parts.d.ts.map +1 -0
- package/dist/chat/parts.js +119 -0
- package/dist/chat/process.d.ts +20 -0
- package/dist/chat/process.d.ts.map +1 -0
- package/dist/chat/process.js +32 -0
- package/dist/chat/provider.d.ts +63 -0
- package/dist/chat/provider.d.ts.map +1 -0
- package/dist/chat/provider.js +628 -0
- package/dist/chat/question.d.ts +9 -0
- package/dist/chat/question.d.ts.map +1 -0
- package/dist/chat/question.js +69 -0
- package/dist/chat/questions.d.ts +31 -0
- package/dist/chat/questions.d.ts.map +1 -0
- package/dist/chat/questions.js +111 -0
- package/dist/chat/read.d.ts +5 -0
- package/dist/chat/read.d.ts.map +1 -0
- package/dist/chat/read.js +13 -0
- package/dist/chat/ready.d.ts +34 -0
- package/dist/chat/ready.d.ts.map +1 -0
- package/dist/chat/ready.js +91 -0
- package/dist/chat/style.d.ts +4 -0
- package/dist/chat/style.d.ts.map +1 -0
- package/dist/chat/style.js +302 -0
- package/dist/chat.d.ts +14 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +8 -0
- package/dist/client.d.ts +30 -13
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +79 -16
- package/dist/collection.d.ts +21 -12
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +301 -23
- package/dist/connection.d.ts +50 -16
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1936 -415
- package/dist/conversation.d.ts +31 -10
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +521 -170
- package/dist/durability.d.ts +7 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +17 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +157 -0
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/fence.d.ts +6 -0
- package/dist/fence.d.ts.map +1 -0
- package/dist/fence.js +10 -0
- package/dist/host.d.ts +15 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +102 -19
- package/dist/identity.d.ts +5 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +19 -1
- package/dist/index.d.ts +16 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/memory.d.ts +11 -4
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +91 -24
- package/dist/model.d.ts +14 -4
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +12 -1
- package/dist/observation.d.ts +7 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +29 -12
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/outcome.d.ts +38 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +45 -1
- package/dist/overlay.d.ts +16 -3
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +118 -77
- package/dist/query.d.ts +60 -4
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +41 -38
- package/dist/reach.d.ts +8 -3
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +73 -24
- package/dist/react.d.ts +31 -20
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +13 -21
- package/dist/read-side.d.ts +16 -7
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +493 -102
- package/dist/readiness.d.ts +53 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +33 -0
- package/dist/reads.d.ts +11 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +98 -0
- package/dist/recovery.d.ts +25 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +197 -0
- package/dist/refresh.d.ts +13 -3
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +49 -38
- package/dist/replica.d.ts +13 -6
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +143 -70
- package/dist/room-draft.d.ts +38 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +134 -25
- package/dist/rows.d.ts +10 -13
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +19 -14
- package/dist/save.d.ts +32 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +390 -45
- package/dist/search.d.ts +52 -8
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +192 -47
- package/dist/seed.d.ts +16 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +75 -0
- package/dist/shared.d.ts +11 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +368 -0
- package/dist/status.d.ts +6 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -8
- package/dist/store.d.ts +89 -18
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +573 -200
- package/dist/turn.d.ts +7 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +51 -0
- package/dist/windows.d.ts +26 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +93 -0
- package/dist/wire.d.ts +157 -33
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +65 -31
- package/package.json +26 -14
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
package/dist/bootstrap.js
CHANGED
|
@@ -1,57 +1,133 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { transferIdentity } from './identity.js';
|
|
2
|
+
import { advancement } from './refresh.js';
|
|
3
|
+
import { acceptedBinaries } from './overlay.js';
|
|
2
4
|
import { readStaged } from './replica.js';
|
|
3
5
|
import { unconfirmed } from './transfer.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const RESUMABLE = new Set([
|
|
7
|
+
'transport-uncertainty',
|
|
8
|
+
'retryable-refusal',
|
|
9
|
+
'unconfirmed',
|
|
10
|
+
]);
|
|
11
|
+
function pageLayer(page) {
|
|
12
|
+
return {
|
|
13
|
+
documents: page.documents,
|
|
14
|
+
revisions: page.revisions,
|
|
15
|
+
fileIds: page.fileIds ?? {},
|
|
16
|
+
changes: page.changes,
|
|
17
|
+
written: Object.fromEntries(Object.keys(page.documents).map((path) => [path, page.roomVersion])),
|
|
18
|
+
binaries: acceptedBinaries(page.binaryFiles),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
async function heldTransfer(staging, room) {
|
|
22
|
+
const record = staging.held(room.locator);
|
|
23
|
+
if (record === null)
|
|
24
|
+
return null;
|
|
25
|
+
if (record.selection === room.replica.selection) {
|
|
26
|
+
return { record, layer: await staging.staged(record) };
|
|
27
|
+
}
|
|
28
|
+
await staging.abandon(room.locator);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
function pooled(pool, layer) {
|
|
32
|
+
return {
|
|
33
|
+
documents: { ...pool?.documents, ...layer.documents },
|
|
34
|
+
revisions: { ...pool?.revisions, ...layer.revisions },
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export async function bootstrapRoom(adapter, authorization, room, held, remodel, continuing, staging, reuse) {
|
|
38
|
+
const first = await bundle(adapter, authorization, room, held, remodel, continuing, staging, await heldTransfer(staging, room), reuse);
|
|
39
|
+
if (first.kind !== 'expired')
|
|
10
40
|
return first;
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
41
|
+
await staging.abandon(room.locator);
|
|
42
|
+
const replacement = await bundle(adapter, authorization, room, held, remodel, continuing, staging, null, pooled(reuse, first.held));
|
|
43
|
+
if (replacement.kind !== 'expired')
|
|
44
|
+
return replacement;
|
|
45
|
+
await staging.abandon(room.locator);
|
|
46
|
+
return unconfirmed;
|
|
47
|
+
}
|
|
48
|
+
async function bundle(adapter, authorization, room, held, remodel, continuing, staging, kept, pool) {
|
|
49
|
+
const locator = room.locator;
|
|
50
|
+
const selection = room.replica.selection;
|
|
51
|
+
const documents = { ...kept?.layer.documents };
|
|
52
|
+
const revisions = { ...kept?.layer.revisions };
|
|
53
|
+
const fileIds = { ...kept?.layer.fileIds };
|
|
54
|
+
const changes = { ...kept?.layer.changes };
|
|
55
|
+
const written = { ...kept?.layer.written };
|
|
56
|
+
const binaries = { ...kept?.layer.binaries };
|
|
57
|
+
let transfer = kept?.record ?? null;
|
|
58
|
+
while (transfer === null || transfer.pageToken !== null) {
|
|
20
59
|
if (!continuing())
|
|
21
60
|
return unconfirmed;
|
|
22
61
|
const page = await adapter.bootstrap(authorization, {
|
|
23
|
-
locator
|
|
24
|
-
selection
|
|
25
|
-
pageToken,
|
|
62
|
+
locator,
|
|
63
|
+
selection,
|
|
64
|
+
...(transfer?.pageToken == null ? {} : { pageToken: transfer.pageToken }),
|
|
65
|
+
...(pool === null ? {} : { held: pool }),
|
|
26
66
|
});
|
|
27
|
-
if (page.kind
|
|
67
|
+
if (page.kind === 'beyond-horizon')
|
|
68
|
+
return { kind: 'expired', held: { documents, revisions } };
|
|
69
|
+
if (page.kind !== 'bootstrap') {
|
|
70
|
+
if (!RESUMABLE.has(page.kind))
|
|
71
|
+
await staging.abandon(locator);
|
|
28
72
|
return page;
|
|
29
|
-
|
|
73
|
+
}
|
|
74
|
+
transfer = {
|
|
75
|
+
locator,
|
|
76
|
+
transfer: transfer?.transfer ?? transferIdentity(),
|
|
77
|
+
selection,
|
|
78
|
+
from: transfer !== null && adapter.reached(locator, page.roomVersion, transfer.from)
|
|
79
|
+
? transfer.from
|
|
80
|
+
: page.roomVersion,
|
|
81
|
+
last: transfer !== null && !adapter.reached(locator, page.roomVersion, transfer.last)
|
|
82
|
+
? transfer.last
|
|
83
|
+
: page.roomVersion,
|
|
84
|
+
pageToken: page.pageToken ?? null,
|
|
85
|
+
models: remodel(page.models, transfer?.models ?? held),
|
|
86
|
+
};
|
|
87
|
+
const staged = pageLayer(page);
|
|
88
|
+
if (!(await staging.stage(transfer, staged)))
|
|
30
89
|
return unconfirmed;
|
|
31
|
-
Object.assign(documents,
|
|
32
|
-
Object.assign(revisions,
|
|
33
|
-
Object.assign(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
pageToken = page.pageToken;
|
|
90
|
+
Object.assign(documents, staged.documents);
|
|
91
|
+
Object.assign(revisions, staged.revisions);
|
|
92
|
+
Object.assign(fileIds, staged.fileIds);
|
|
93
|
+
Object.assign(changes, staged.changes);
|
|
94
|
+
Object.assign(written, staged.written);
|
|
95
|
+
Object.assign(binaries, staged.binaries);
|
|
38
96
|
}
|
|
39
|
-
|
|
40
|
-
locator
|
|
97
|
+
const record = {
|
|
98
|
+
locator,
|
|
41
99
|
name: room.name,
|
|
42
100
|
handle: room.handle,
|
|
43
101
|
operations: room.operations,
|
|
44
102
|
replica: room.replica,
|
|
45
|
-
model: models.collection,
|
|
103
|
+
model: transfer.models.collection,
|
|
46
104
|
typedSelection: room.typedSelection ?? null,
|
|
47
|
-
selectionModel: models.selection,
|
|
105
|
+
selectionModel: transfer.models.selection,
|
|
48
106
|
providerOwnedPaths: room.providerOwnedPaths,
|
|
49
|
-
roomVersion,
|
|
107
|
+
roomVersion: transfer.from,
|
|
108
|
+
transfer: transfer.transfer,
|
|
50
109
|
documents,
|
|
51
|
-
|
|
110
|
+
binaries,
|
|
52
111
|
revisions,
|
|
112
|
+
fileIds,
|
|
53
113
|
changes,
|
|
54
|
-
written
|
|
55
|
-
|
|
56
|
-
|
|
114
|
+
written,
|
|
115
|
+
};
|
|
116
|
+
const reconciled = transfer.last === transfer.from
|
|
117
|
+
? { kind: 'still-current' }
|
|
118
|
+
: await advancement(adapter, authorization, record, remodel, continuing);
|
|
119
|
+
if (reconciled.kind === 'advanced' || reconciled.kind === 'still-current') {
|
|
120
|
+
const read = readStaged(reconciled.kind === 'advanced' ? reconciled.record : record);
|
|
121
|
+
if (read.kind === 'refused') {
|
|
122
|
+
await staging.abandon(locator);
|
|
123
|
+
return read;
|
|
124
|
+
}
|
|
125
|
+
return { kind: 'staged', confirmed: read.confirmed, stored: record };
|
|
126
|
+
}
|
|
127
|
+
if (reconciled.kind === 'beyond-horizon') {
|
|
128
|
+
return { kind: 'expired', held: { documents, revisions } };
|
|
129
|
+
}
|
|
130
|
+
if (!RESUMABLE.has(reconciled.kind))
|
|
131
|
+
await staging.abandon(locator);
|
|
132
|
+
return reconciled;
|
|
57
133
|
}
|
package/dist/change-set.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export type DocumentChange = {
|
|
|
9
9
|
export type MessageChange = {
|
|
10
10
|
conversation: string;
|
|
11
11
|
identity: string;
|
|
12
|
+
text: string | null;
|
|
12
13
|
};
|
|
13
14
|
export type ChangeSet = {
|
|
14
15
|
documents: readonly DocumentChange[];
|
|
@@ -28,6 +29,7 @@ export declare function changeSet(locator: string, before: Replica | null, after
|
|
|
28
29
|
queue?: boolean;
|
|
29
30
|
presentation?: string;
|
|
30
31
|
}): ChangeSet;
|
|
32
|
+
export declare function entering(locator: string, replica: Replica, paths: readonly string[]): ChangeSet;
|
|
31
33
|
export declare function conversationChangeSet(messages: readonly MessageChange[], conversations: readonly string[]): ChangeSet;
|
|
32
34
|
export declare function mergeChangeSets(sets: readonly ChangeSet[]): ChangeSet;
|
|
33
35
|
//# sourceMappingURL=change-set.d.ts.map
|
package/dist/change-set.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"change-set.d.ts","sourceRoot":"","sources":["../src/change-set.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"change-set.d.ts","sourceRoot":"","sources":["../src/change-set.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiC,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAwB,KAAK,GAAG,EAAE,MAAM,WAAW,CAAC;AAE3D,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,GAAG,EAAE,CAAC;IACvB,KAAK,EAAE,SAAS,GAAG,EAAE,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAE5F,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,EAAE,SAAS,cAAc,EAAE,CAAC;IACrC,MAAM,EAAE,SAAS;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACrD,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAC;IACnC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC,CAAC;AAwBF,wBAAgB,SAAS,CACvB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,OAAO,GAAG,IAAI,EACtB,KAAK,EAAE,OAAO,GAAG,IAAI,EACrB,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CAClB,GACL,SAAS,CA+DX;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAiB/F;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,SAAS,aAAa,EAAE,EAClC,aAAa,EAAE,SAAS,MAAM,EAAE,GAC/B,SAAS,CAUX;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,CAUrE"}
|
package/dist/change-set.js
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { passingFrontmatter } from './collection.js';
|
|
2
|
+
import { binaryRecord } from './binary.js';
|
|
3
|
+
import { changedPaths, sameBinary, sameChange } from './overlay.js';
|
|
2
4
|
import { beneath } from './paths.js';
|
|
3
5
|
import { compositionOf, sameMembership } from './replica.js';
|
|
4
|
-
import { rowsOf } from './rows.js';
|
|
6
|
+
import { markdownPath, rowsOf } from './rows.js';
|
|
5
7
|
function rowsAt(locator, replica, path) {
|
|
6
8
|
if (replica === null)
|
|
7
9
|
return [];
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
+
const visible = replica.visible;
|
|
11
|
+
const document = markdownPath(path) ? passingFrontmatter(visible.collection, path) : null;
|
|
12
|
+
const held = visible.documents[path] !== undefined && document !== undefined;
|
|
13
|
+
const binary = visible.binaries[path];
|
|
14
|
+
if (!held && binary === undefined)
|
|
10
15
|
return [];
|
|
11
|
-
|
|
12
|
-
return rowsOf(locator, path, document ?? null, compositionOf(replica.confirmed.record), replica.visible.changes[path] ?? null);
|
|
16
|
+
return rowsOf(locator, path, document ?? null, compositionOf(replica.confirmed.record), visible.changes[path] ?? null, visible.fileIds[path] ?? null, binary === undefined ? null : binaryRecord(path, binary, visible.revisions[path]));
|
|
13
17
|
}
|
|
14
18
|
function modelShape(model) {
|
|
15
19
|
return model.status === 'unavailable' ? 'unavailable' : JSON.stringify(model.types);
|
|
16
20
|
}
|
|
17
21
|
export function changeSet(locator, before, after, changed = {}) {
|
|
18
|
-
const paths = new Set([
|
|
19
|
-
...Object.keys(before?.visible.documents ?? {}),
|
|
20
|
-
...Object.keys(after?.visible.documents ?? {}),
|
|
21
|
-
...(before?.visible.binaryTargets ?? []),
|
|
22
|
-
...(after?.visible.binaryTargets ?? []),
|
|
23
|
-
]);
|
|
24
22
|
const documents = [];
|
|
25
23
|
const oldRoom = before?.confirmed.record;
|
|
26
24
|
const newRoom = after?.confirmed.record;
|
|
@@ -31,13 +29,26 @@ export function changeSet(locator, before, after, changed = {}) {
|
|
|
31
29
|
newRoom !== undefined &&
|
|
32
30
|
modelShape(oldRoom.selectionModel) !== modelShape(newRoom.selectionModel);
|
|
33
31
|
const reclassified = oldRoom !== undefined && newRoom !== undefined && !sameMembership(oldRoom, newRoom);
|
|
32
|
+
const paths = before === null || after === null || collectionChanged || selectionChanged || reclassified
|
|
33
|
+
? new Set([
|
|
34
|
+
...Object.keys(before?.visible.documents ?? {}),
|
|
35
|
+
...Object.keys(after?.visible.documents ?? {}),
|
|
36
|
+
...Object.keys(before?.visible.binaries ?? {}),
|
|
37
|
+
...Object.keys(after?.visible.binaries ?? {}),
|
|
38
|
+
])
|
|
39
|
+
: changedPaths(before.visible, after.visible);
|
|
34
40
|
for (const path of paths) {
|
|
41
|
+
if (after?.visible.documents[path] === undefined &&
|
|
42
|
+
after?.visible.binaries[path] === undefined &&
|
|
43
|
+
before?.visible.documents[path] === undefined &&
|
|
44
|
+
before?.visible.binaries[path] === undefined)
|
|
45
|
+
continue;
|
|
35
46
|
const selected = newRoom?.typedSelection?.roots.some((root) => beneath(root, path)) ?? false;
|
|
36
47
|
const retyped = selected ? selectionChanged : collectionChanged;
|
|
37
48
|
if (before?.visible.documents[path] === after?.visible.documents[path] &&
|
|
38
|
-
before?.visible.
|
|
39
|
-
after?.visible.binaryTargets.includes(path) &&
|
|
49
|
+
sameBinary(before?.visible.binaries[path], after?.visible.binaries[path]) &&
|
|
40
50
|
before?.visible.revisions[path] === after?.visible.revisions[path] &&
|
|
51
|
+
before?.visible.fileIds[path] === after?.visible.fileIds[path] &&
|
|
41
52
|
sameChange(before?.visible.changes[path], after?.visible.changes[path]) &&
|
|
42
53
|
!retyped &&
|
|
43
54
|
!reclassified)
|
|
@@ -45,8 +56,12 @@ export function changeSet(locator, before, after, changed = {}) {
|
|
|
45
56
|
documents.push({
|
|
46
57
|
locator,
|
|
47
58
|
path,
|
|
48
|
-
before
|
|
49
|
-
|
|
59
|
+
get before() {
|
|
60
|
+
return rowsAt(locator, before, path);
|
|
61
|
+
},
|
|
62
|
+
get after() {
|
|
63
|
+
return rowsAt(locator, after, path);
|
|
64
|
+
},
|
|
50
65
|
});
|
|
51
66
|
}
|
|
52
67
|
return {
|
|
@@ -59,6 +74,24 @@ export function changeSet(locator, before, after, changed = {}) {
|
|
|
59
74
|
conversations: [],
|
|
60
75
|
};
|
|
61
76
|
}
|
|
77
|
+
export function entering(locator, replica, paths) {
|
|
78
|
+
return {
|
|
79
|
+
documents: paths.map((path) => ({
|
|
80
|
+
locator,
|
|
81
|
+
path,
|
|
82
|
+
before: [],
|
|
83
|
+
get after() {
|
|
84
|
+
return rowsAt(locator, replica, path);
|
|
85
|
+
},
|
|
86
|
+
})),
|
|
87
|
+
drafts: [],
|
|
88
|
+
rooms: [],
|
|
89
|
+
queues: [],
|
|
90
|
+
presentations: [],
|
|
91
|
+
messages: [],
|
|
92
|
+
conversations: [],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
62
95
|
export function conversationChangeSet(messages, conversations) {
|
|
63
96
|
return {
|
|
64
97
|
documents: [],
|
package/dist/change.d.ts
CHANGED
|
@@ -25,6 +25,14 @@ export type Change = {
|
|
|
25
25
|
readonly kind: 'replace';
|
|
26
26
|
readonly path: string;
|
|
27
27
|
readonly content: string;
|
|
28
|
+
} | {
|
|
29
|
+
readonly kind: 'binary';
|
|
30
|
+
readonly path: string;
|
|
31
|
+
readonly localId: string;
|
|
32
|
+
readonly blob: Blob;
|
|
33
|
+
readonly byteLength: number;
|
|
34
|
+
readonly mediaType: string;
|
|
35
|
+
readonly sha256: string;
|
|
28
36
|
} | {
|
|
29
37
|
readonly kind: 'move';
|
|
30
38
|
readonly path: string;
|
|
@@ -51,6 +59,10 @@ export type Precondition = {
|
|
|
51
59
|
readonly kind: 'revision';
|
|
52
60
|
readonly path: string;
|
|
53
61
|
readonly revision: string;
|
|
62
|
+
} | {
|
|
63
|
+
readonly kind: 'content';
|
|
64
|
+
readonly path: string;
|
|
65
|
+
readonly content: string;
|
|
54
66
|
} | {
|
|
55
67
|
readonly kind: 'present';
|
|
56
68
|
readonly path: string;
|
|
@@ -71,4 +83,7 @@ export type ChangeBatch = {
|
|
|
71
83
|
readonly writtenBy?: WrittenBy;
|
|
72
84
|
};
|
|
73
85
|
export declare function immutable(batch: ChangeBatch): ChangeBatch;
|
|
86
|
+
export declare function landing(changes: readonly Change[], index: number, path: string): string | null;
|
|
87
|
+
export declare function departure(changes: readonly Change[], index: number): string;
|
|
88
|
+
export declare function queuedFile(batch: ChangeBatch, path: string, localId: string): number;
|
|
74
89
|
//# sourceMappingURL=change.d.ts.map
|
package/dist/change.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"change.d.ts","sourceRoot":"","sources":["../src/change.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GACd;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,GACD;I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EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAOpF"}
|
package/dist/change.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function frozen(value) {
|
|
2
2
|
if (Array.isArray(value))
|
|
3
3
|
return Object.freeze(value.map((item) => frozen(item)));
|
|
4
|
-
if (value === null || typeof value !== 'object')
|
|
4
|
+
if (value === null || typeof value !== 'object' || value instanceof Blob)
|
|
5
5
|
return value;
|
|
6
6
|
const copy = {};
|
|
7
7
|
for (const [name, item] of Object.entries(value))
|
|
@@ -11,3 +11,28 @@ function frozen(value) {
|
|
|
11
11
|
export function immutable(batch) {
|
|
12
12
|
return frozen(batch);
|
|
13
13
|
}
|
|
14
|
+
export function landing(changes, index, path) {
|
|
15
|
+
let at = path;
|
|
16
|
+
for (const change of changes.slice(index + 1)) {
|
|
17
|
+
if (change.path !== at)
|
|
18
|
+
continue;
|
|
19
|
+
if (change.kind === 'remove')
|
|
20
|
+
return null;
|
|
21
|
+
if (change.kind === 'move')
|
|
22
|
+
at = change.to;
|
|
23
|
+
}
|
|
24
|
+
return at;
|
|
25
|
+
}
|
|
26
|
+
export function departure(changes, index) {
|
|
27
|
+
let at = changes[index].path;
|
|
28
|
+
for (const change of changes.slice(0, index).reverse()) {
|
|
29
|
+
if (change.kind === 'move' && change.to === at)
|
|
30
|
+
at = change.path;
|
|
31
|
+
}
|
|
32
|
+
return at;
|
|
33
|
+
}
|
|
34
|
+
export function queuedFile(batch, path, localId) {
|
|
35
|
+
return batch.changes.findIndex((change, index) => change.kind === 'binary' &&
|
|
36
|
+
change.localId === localId &&
|
|
37
|
+
landing(batch.changes, index, change.path) === path);
|
|
38
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Answered } from '../attempt.js';
|
|
2
|
+
import { type CallResult, type Offline } from '../outcome.js';
|
|
3
|
+
import type { Expected } from './overlay.js';
|
|
4
|
+
export type ChatResult = CallResult | Offline;
|
|
5
|
+
export type ChatOutcome = {
|
|
6
|
+
readonly state: 'sending';
|
|
7
|
+
} | {
|
|
8
|
+
readonly state: 'offline';
|
|
9
|
+
} | {
|
|
10
|
+
readonly state: 'failed';
|
|
11
|
+
readonly result: CallResult;
|
|
12
|
+
};
|
|
13
|
+
export declare function accepted(result: ChatResult): result is Extract<CallResult, {
|
|
14
|
+
readonly kind: 'action';
|
|
15
|
+
}>;
|
|
16
|
+
export declare function unanswered(result: ChatResult): boolean;
|
|
17
|
+
export declare function outcomeOf(result: ChatResult): ChatOutcome | null;
|
|
18
|
+
export declare function answeredOf(result: ChatResult): Answered;
|
|
19
|
+
export type Sender = {
|
|
20
|
+
carried(name: string, about: unknown, sending: (operation: string) => Promise<CallResult>): Promise<ChatResult>;
|
|
21
|
+
numbered(name: string, about: unknown, sending: (operation: string) => Promise<ChatResult>): Promise<ChatResult>;
|
|
22
|
+
expect(expected: Expected): void;
|
|
23
|
+
draw(expected: Expected): void;
|
|
24
|
+
};
|
|
25
|
+
type Senders = {
|
|
26
|
+
readonly online: boolean;
|
|
27
|
+
identity(intent: string): string;
|
|
28
|
+
expect(expected: Expected): void;
|
|
29
|
+
draw(expected: Expected): void;
|
|
30
|
+
};
|
|
31
|
+
export declare function sender({ online, identity, expect, draw }: Senders): Sender;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=acts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acts.d.ts","sourceRoot":"","sources":["../../src/chat/acts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAa,KAAK,UAAU,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC;AAE9C,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,KAA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,EAAE,QAAQ,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,wBAAgB,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,OAAO,GAAG,MAAM,CAe1E"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { intentOf } from '../attempt.js';
|
|
2
|
+
import { UNCERTAIN } from '../outcome.js';
|
|
3
|
+
export function accepted(result) {
|
|
4
|
+
return result.kind === 'action';
|
|
5
|
+
}
|
|
6
|
+
export function unanswered(result) {
|
|
7
|
+
return result.kind === 'transport-uncertainty';
|
|
8
|
+
}
|
|
9
|
+
export function outcomeOf(result) {
|
|
10
|
+
if (accepted(result))
|
|
11
|
+
return null;
|
|
12
|
+
return result.kind === 'offline' ? { state: 'offline' } : { state: 'failed', result };
|
|
13
|
+
}
|
|
14
|
+
export function answeredOf(result) {
|
|
15
|
+
if (accepted(result))
|
|
16
|
+
return 'accepted';
|
|
17
|
+
if (result.kind === 'offline')
|
|
18
|
+
return 'offline';
|
|
19
|
+
return unanswered(result) ? 'unanswered' : 'refused';
|
|
20
|
+
}
|
|
21
|
+
export function sender({ online, identity, expect, draw }) {
|
|
22
|
+
const numbered = async (name, about, sending) => {
|
|
23
|
+
try {
|
|
24
|
+
return await sending(identity(intentOf(name, about)));
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return UNCERTAIN;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
carried: (name, about, sending) => online ? numbered(name, about, sending) : Promise.resolve({ kind: 'offline' }),
|
|
32
|
+
numbered,
|
|
33
|
+
expect,
|
|
34
|
+
draw,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/chat/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAQjD,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAExD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function figure(tokens) {
|
|
2
|
+
if (tokens >= 1_000_000)
|
|
3
|
+
return `${(tokens / 1_000_000).toFixed(1).replace(/\.0$/, '')}M`;
|
|
4
|
+
if (tokens >= 1_000)
|
|
5
|
+
return `${Math.round(tokens / 1_000)}k`;
|
|
6
|
+
return String(tokens);
|
|
7
|
+
}
|
|
8
|
+
export function contextText(context) {
|
|
9
|
+
return `${figure(context.used)}/${figure(context.window)}`;
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MdRuntimeClient } from '../client.js';
|
|
2
|
+
import type { ConversationView } from '../conversation.js';
|
|
3
|
+
export declare const CHAT_WINDOW = 50;
|
|
4
|
+
export type Paged = {
|
|
5
|
+
readonly view: ConversationView | null;
|
|
6
|
+
readonly hasEarlier: boolean;
|
|
7
|
+
loadEarlier(): Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
export declare function useEarlier(client: MdRuntimeClient, thread: string | null, held: ConversationView | null): Paged;
|
|
10
|
+
//# sourceMappingURL=earlier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"earlier.d.ts","sourceRoot":"","sources":["../../src/chat/earlier.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,eAAO,MAAM,WAAW,KAAK,CAAC;AAU9B,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC;AAuBF,wBAAgB,UAAU,CACxB,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAC5B,KAAK,CA8BP"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
export const CHAT_WINDOW = 50;
|
|
3
|
+
function slidOut(before, after) {
|
|
4
|
+
if (before === null || before.conversation !== after.conversation)
|
|
5
|
+
return [];
|
|
6
|
+
const kept = new Set(after.messages.map((one) => one.identity));
|
|
7
|
+
const left = [];
|
|
8
|
+
for (const message of before.messages) {
|
|
9
|
+
if (kept.has(message.identity))
|
|
10
|
+
break;
|
|
11
|
+
left.push(message);
|
|
12
|
+
}
|
|
13
|
+
return left;
|
|
14
|
+
}
|
|
15
|
+
function joined(held, earlier) {
|
|
16
|
+
const { next: _live, ...view } = held;
|
|
17
|
+
const live = new Set(held.messages.map((one) => one.identity));
|
|
18
|
+
return {
|
|
19
|
+
...view,
|
|
20
|
+
messages: [...earlier.messages.filter((one) => !live.has(one.identity)), ...held.messages],
|
|
21
|
+
...(earlier.next === undefined ? {} : { next: earlier.next }),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function useEarlier(client, thread, held) {
|
|
25
|
+
const [earlier, setEarlier] = useState(null);
|
|
26
|
+
const [seen, setSeen] = useState(held);
|
|
27
|
+
const whole = held !== null && held.next === undefined;
|
|
28
|
+
let current = earlier !== null && earlier.thread === thread && !whole ? earlier : null;
|
|
29
|
+
if (current !== earlier)
|
|
30
|
+
setEarlier(current);
|
|
31
|
+
if (seen !== held) {
|
|
32
|
+
setSeen(held);
|
|
33
|
+
const carried = held === null ? [] : slidOut(seen, held);
|
|
34
|
+
if (thread !== null && carried.length > 0) {
|
|
35
|
+
const base = current ?? { thread, messages: [], next: seen?.next };
|
|
36
|
+
current = { ...base, messages: [...base.messages, ...carried] };
|
|
37
|
+
setEarlier(current);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const view = useMemo(() => (held === null || current === null ? held : joined(held, current)), [held, current]);
|
|
41
|
+
const next = current === null ? held?.next : current.next;
|
|
42
|
+
const loadEarlier = useCallback(async () => {
|
|
43
|
+
if (thread === null || next === undefined)
|
|
44
|
+
return;
|
|
45
|
+
const older = await client.conversation.read(thread, { limit: CHAT_WINDOW, after: next });
|
|
46
|
+
setEarlier((now) => {
|
|
47
|
+
const base = now !== null && now.thread === thread ? now : { thread, messages: [], next };
|
|
48
|
+
if (base.next !== next)
|
|
49
|
+
return now;
|
|
50
|
+
return { thread, messages: [...older.messages, ...base.messages], next: older.next };
|
|
51
|
+
});
|
|
52
|
+
}, [client, thread, next]);
|
|
53
|
+
return { view, hasEarlier: next !== undefined, loadEarlier };
|
|
54
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
import { type ChatNoteProps } from './kit.js';
|
|
3
|
+
export type ChatInputProps = {
|
|
4
|
+
readonly messageLength?: number;
|
|
5
|
+
readonly note?: (note: ChatNoteProps) => ReactNode;
|
|
6
|
+
readonly autoFocus?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function ChatInput({ messageLength, note, autoFocus, }: ChatInputProps): ReactElement;
|
|
9
|
+
//# sourceMappingURL=input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/chat/input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA0C,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAqBlG,OAAO,EAAsD,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAMlG,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,SAAS,CAAC;IACnD,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAiGF,wBAAgB,SAAS,CAAC,EACxB,aAAa,EACb,IAAY,EACZ,SAAiB,GAClB,EAAE,cAAc,GAAG,YAAY,CA+K/B"}
|