@agentshouse/mdruntime 0.1.0-c0ffc146f48dd → 0.1.0-c112fd663ab59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/dist/acceptance.d.ts +6 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +385 -0
- package/dist/actions.d.ts +20 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +251 -0
- package/dist/adapter.d.ts +45 -25
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +3 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +21 -56
- package/dist/bootstrap.d.ts +8 -4
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +210 -78
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -0
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/change.d.ts +1 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +4 -2
- package/dist/chat-types.d.ts +5 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +13 -0
- package/dist/client.d.ts +22 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +7 -2
- package/dist/collection.d.ts +2 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/compile.d.ts +6 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +240 -315
- package/dist/connection.d.ts +5 -142
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +103 -5071
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation-live.d.ts +136 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +248 -0
- package/dist/conversation-row.d.ts +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +53 -0
- package/dist/conversation.d.ts +34 -38
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +861 -850
- package/dist/discovery.d.ts +10 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +175 -0
- package/dist/durability.d.ts +15 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +2 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +17 -7
- package/dist/expectation.d.ts +4 -2
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +33 -11
- package/dist/failure.d.ts +1 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/holdings.d.ts +29 -0
- package/dist/holdings.d.ts.map +1 -0
- package/dist/holdings.js +95 -0
- package/dist/host.d.ts +4 -5
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +23 -22
- package/dist/identity.d.ts +0 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -3
- package/dist/index.d.ts +25 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/install.d.ts +56 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +556 -0
- package/dist/job.d.ts +33 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +54 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +270 -0
- package/dist/listing.d.ts +53 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +176 -0
- package/dist/live.d.ts +5 -4
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +63 -21
- package/dist/locks.d.ts +9 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +62 -0
- package/dist/log.d.ts +1 -0
- package/dist/log.d.ts.map +1 -1
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +61 -0
- package/dist/media.d.ts +1 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +3 -3
- package/dist/memory.d.ts +5 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +50 -10
- package/dist/messages.d.ts +27 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +103 -31
- package/dist/model.d.ts +2 -9
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -9
- package/dist/models.d.ts +14 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +197 -0
- package/dist/observation.d.ts +2 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +14 -14
- package/dist/opened.js +3 -3
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +60 -0
- package/dist/outcome.d.ts +4 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +3 -0
- package/dist/overlay.d.ts +1 -0
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +11 -0
- package/dist/parts.d.ts +60 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +126 -0
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +22 -0
- package/dist/preparation.d.ts +20 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +233 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +272 -0
- package/dist/query.d.ts +13 -209
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- package/dist/questions.d.ts +34 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +122 -0
- package/dist/reach.d.ts +14 -12
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +167 -114
- package/dist/react.d.ts +13 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +10 -1
- package/dist/read.d.ts +7 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +17 -0
- package/dist/readiness.d.ts +0 -3
- package/dist/readiness.d.ts.map +1 -1
- package/dist/reads.d.ts +37 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +174 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +9 -1
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +7 -0
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +57 -0
- package/dist/replica.d.ts +9 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +53 -17
- package/dist/room-draft.d.ts +3 -4
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +7 -7
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +217 -0
- package/dist/rows.d.ts +14 -21
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +48 -184
- package/dist/runtime.d.ts +43 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +5 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +34 -21
- package/dist/saves.d.ts +70 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +1005 -0
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/seed.d.ts +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +71 -1
- package/dist/shared.d.ts +1 -6
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -95
- package/dist/shown.d.ts +31 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +290 -0
- package/dist/socket/admission.d.ts +7 -0
- package/dist/socket/admission.d.ts.map +1 -0
- package/dist/socket/admission.js +39 -0
- package/dist/socket/answers.d.ts +6 -0
- package/dist/socket/answers.d.ts.map +1 -0
- package/dist/socket/answers.js +20 -0
- package/dist/socket/lanes.d.ts +20 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +77 -0
- package/dist/socket/reads.d.ts +10 -0
- package/dist/socket/reads.d.ts.map +1 -0
- package/dist/socket/reads.js +31 -0
- package/dist/socket/rooms.d.ts +44 -0
- package/dist/socket/rooms.d.ts.map +1 -0
- package/dist/socket/rooms.js +90 -0
- package/dist/socket/session.d.ts +38 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +23 -0
- package/dist/socket.d.ts +70 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +175 -0
- package/dist/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +82 -0
- package/dist/status.d.ts +0 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -6
- package/dist/store/fences.d.ts +16 -0
- package/dist/store/fences.d.ts.map +1 -0
- package/dist/store/fences.js +26 -0
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +34 -0
- package/dist/store/readiness.d.ts +10 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +52 -0
- package/dist/store/records.d.ts +212 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +431 -0
- package/dist/store/room-held.d.ts +8 -0
- package/dist/store/room-held.d.ts.map +1 -0
- package/dist/store/room-held.js +17 -0
- package/dist/store/space.d.ts +11 -0
- package/dist/store/space.d.ts.map +1 -0
- package/dist/store/space.js +41 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +56 -0
- package/dist/store/writes.d.ts +24 -0
- package/dist/store/writes.d.ts.map +1 -0
- package/dist/store/writes.js +125 -0
- package/dist/store.d.ts +107 -145
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +143 -366
- package/dist/stored.d.ts +59 -33
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +278 -189
- package/dist/surface.d.ts +88 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +224 -0
- package/dist/sync.d.ts +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +532 -0
- package/dist/tables.d.ts +120 -29
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +216 -54
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +129 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +7 -4
- package/dist/windows.d.ts +1 -12
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -75
- package/dist/wire.d.ts +16 -1
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +6 -0
- package/package.json +2 -2
- package/dist/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -370
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -156
package/README.md
CHANGED
|
@@ -12,14 +12,14 @@ npm install @agentshouse/mdruntime
|
|
|
12
12
|
|
|
13
13
|
## Entries
|
|
14
14
|
|
|
15
|
-
| Entry | For
|
|
16
|
-
| ------------------------------- |
|
|
17
|
-
| `@agentshouse/mdruntime/client` | The host's client: `connectMdRuntime(port)`
|
|
18
|
-
| `@agentshouse/mdruntime/host` | The host that serves a Runtime: `serveMdRuntime`
|
|
19
|
-
| `@agentshouse/mdruntime` | Shared types
|
|
20
|
-
| `@agentshouse/mdruntime/memory` | Tests: `createMemoryAdapter`, an in-memory Adapter
|
|
21
|
-
| `@agentshouse/mdruntime/tables` | The host's database: the Authored store's and opened files' tables, `answerRuntime`
|
|
22
|
-
| `@agentshouse/mdruntime/react` | React over the client: `useObserve`, `useSave`
|
|
15
|
+
| Entry | For |
|
|
16
|
+
| ------------------------------- | ---------------------------------------------------------------------------------------------- |
|
|
17
|
+
| `@agentshouse/mdruntime/client` | The host's client: `connectMdRuntime(port)` |
|
|
18
|
+
| `@agentshouse/mdruntime/host` | The host that serves a Runtime: `serveMdRuntime` |
|
|
19
|
+
| `@agentshouse/mdruntime` | Shared types |
|
|
20
|
+
| `@agentshouse/mdruntime/memory` | Tests: `createMemoryAdapter`, an in-memory Adapter |
|
|
21
|
+
| `@agentshouse/mdruntime/tables` | The host's database: the Authored store's and opened files' tables, `answerRuntime` |
|
|
22
|
+
| `@agentshouse/mdruntime/react` | React over the client: `useObserve`, `useSave`; `useReading`, a reader of an expectation store |
|
|
23
23
|
|
|
24
24
|
## Usage
|
|
25
25
|
|
|
@@ -48,9 +48,9 @@ chat.update({ width: 'full', showChats: true });
|
|
|
48
48
|
chat.unmount();
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
The rules an App's agent follows, including Local Query,
|
|
51
|
+
The rules an App's agent follows, including Local Query, search, Room
|
|
52
52
|
Draft, Save and the Chat, are the `apps/` pages of House's Guide, which House's
|
|
53
|
-
`
|
|
53
|
+
`guide/open` opens.
|
|
54
54
|
|
|
55
55
|
## License
|
|
56
56
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Runtime } from './runtime.js';
|
|
2
|
+
import type { RuntimeStore } from './store.js';
|
|
3
|
+
export declare function unpair(runtime: Runtime, local: RuntimeStore): Promise<void>;
|
|
4
|
+
export declare function submitLater(runtime: Runtime, locator: string): void;
|
|
5
|
+
export declare function submitAll(runtime: Runtime): Promise<void>;
|
|
6
|
+
//# sourceMappingURL=acceptance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acceptance.d.ts","sourceRoot":"","sources":["../src/acceptance.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,YAAY,CAAC;AAkO5D,wBAAsB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBjF;AA+ND,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,QAK5D;AA4BD,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,iBAM/C"}
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { changeSet } from './change-set.js';
|
|
2
|
+
import { leaving as leavingIn, partnerOf } from './change.js';
|
|
3
|
+
import { olderThan, showing } from './install.js';
|
|
4
|
+
import { readable } from './listing.js';
|
|
5
|
+
import { refuse } from './refusal.js';
|
|
6
|
+
import { landed, returnedPaths, returning, slicing, touchedBy } from './replica.js';
|
|
7
|
+
import { batchFile, landedWhole, settle, settlement, sliceAt, together, unpairing, withdrawable, } from './saves.js';
|
|
8
|
+
import { rest, roomUnreadable, statusShown } from './shown.js';
|
|
9
|
+
import { unconfirmed } from './transfer.js';
|
|
10
|
+
import { stepped } from './turn.js';
|
|
11
|
+
function pendingKey(locator, id) {
|
|
12
|
+
return `${locator}\u0000${id}`;
|
|
13
|
+
}
|
|
14
|
+
async function mark(runtime, local, locator, batch, submission, lost) {
|
|
15
|
+
const { store, socket } = runtime;
|
|
16
|
+
const partner = partnerOf(batch, locator);
|
|
17
|
+
for (const held of partner === null ? [locator] : [locator, partner]) {
|
|
18
|
+
const { state, room } = await local.pending(held, batch.id);
|
|
19
|
+
if (!socket.continuing() ||
|
|
20
|
+
state === undefined ||
|
|
21
|
+
(JSON.stringify(state.submission) === JSON.stringify(submission) && state.lost === lost)) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
await local.submit(held, batch.id, submission, lost);
|
|
25
|
+
if (store.fences.has(held))
|
|
26
|
+
continue;
|
|
27
|
+
if (room)
|
|
28
|
+
store.changed(changeSet(held, { queue: true }));
|
|
29
|
+
}
|
|
30
|
+
statusShown(runtime);
|
|
31
|
+
}
|
|
32
|
+
async function keepUpload({ store, socket }, local, locator, identifier, upload) {
|
|
33
|
+
if (!socket.continuing())
|
|
34
|
+
throw new Error();
|
|
35
|
+
await local.keepUpload(locator, identifier, upload);
|
|
36
|
+
if (store.fences.has(locator))
|
|
37
|
+
throw new Error();
|
|
38
|
+
if (!socket.continuing())
|
|
39
|
+
throw new Error();
|
|
40
|
+
}
|
|
41
|
+
function leaving(batch, result) {
|
|
42
|
+
return {
|
|
43
|
+
batch,
|
|
44
|
+
returned: {
|
|
45
|
+
kind: result.kind,
|
|
46
|
+
code: result.code,
|
|
47
|
+
fields: result.fields,
|
|
48
|
+
retryable: result.retryable,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function logAccepted({ journal }, locator, submitted, accepted) {
|
|
53
|
+
journal.record(`outcome ${locator} ${submitted.id} accepted ${accepted.roomVersion}` +
|
|
54
|
+
(accepted.author === undefined ? '' : ` author ${accepted.author}`) +
|
|
55
|
+
(accepted.time === undefined ? '' : ` time ${accepted.time}`));
|
|
56
|
+
}
|
|
57
|
+
function settling(acceptance) {
|
|
58
|
+
return acceptance !== null && 'apply' in acceptance;
|
|
59
|
+
}
|
|
60
|
+
function failureOf(acceptance) {
|
|
61
|
+
return settling(acceptance) ? null : acceptance;
|
|
62
|
+
}
|
|
63
|
+
async function acceptance(runtime, room, local, submitted, accepted) {
|
|
64
|
+
const { store, socket } = runtime;
|
|
65
|
+
if (!socket.continuing())
|
|
66
|
+
return unconfirmed;
|
|
67
|
+
const work = await store.work(room.locator);
|
|
68
|
+
const current = work.replica;
|
|
69
|
+
if (current === undefined || !current.queue.some((batch) => batch.id === submitted.id)) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const held = current.record.roomVersion;
|
|
73
|
+
logAccepted(runtime, room.locator, submitted, accepted);
|
|
74
|
+
let record = current.record;
|
|
75
|
+
let changes;
|
|
76
|
+
if (!socket.reads.reached(room.locator, held, accepted.roomVersion) &&
|
|
77
|
+
!olderThan(runtime, room.locator, accepted.roomVersion, held)) {
|
|
78
|
+
const paths = [...returnedPaths(submitted, accepted)];
|
|
79
|
+
const confirmedLayer = await stepped(slicing(await local.entries(record.key, 'confirmed', paths), paths));
|
|
80
|
+
const back = await stepped(returning(confirmedLayer, submitted, accepted, accepted.roomVersion, store.composed(record)));
|
|
81
|
+
record = {
|
|
82
|
+
...record,
|
|
83
|
+
roomVersion: socket.follows(room.locator, held, accepted.roomVersion)
|
|
84
|
+
? accepted.roomVersion
|
|
85
|
+
: held,
|
|
86
|
+
};
|
|
87
|
+
changes = back;
|
|
88
|
+
}
|
|
89
|
+
const settled = await settlement(runtime, local, room.locator, work, record, current.queue.filter((batch) => batch.id !== submitted.id), { room: true, ...(changes === undefined ? {} : { changes }) });
|
|
90
|
+
const reached = record.roomVersion;
|
|
91
|
+
return {
|
|
92
|
+
...settled,
|
|
93
|
+
apply(answer) {
|
|
94
|
+
const set = settled.apply(answer);
|
|
95
|
+
showing(runtime, room.locator, accepted.roomVersion, reached);
|
|
96
|
+
readable(runtime, room);
|
|
97
|
+
return set;
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async function adoptedTogether(runtime, local, acceptances) {
|
|
102
|
+
const settlements = acceptances.filter(settling);
|
|
103
|
+
if (settlements.length > 0) {
|
|
104
|
+
const set = await together(runtime, local, settlements);
|
|
105
|
+
void statusShown(runtime);
|
|
106
|
+
void runtime.store.changed(set);
|
|
107
|
+
}
|
|
108
|
+
await unpair(runtime, local);
|
|
109
|
+
}
|
|
110
|
+
async function adopted(runtime, room, local, submitted, accepted) {
|
|
111
|
+
const failed = await runtime.store.exclusive(async () => {
|
|
112
|
+
const adopting = await acceptance(runtime, room, local, submitted, accepted);
|
|
113
|
+
await adoptedTogether(runtime, local, [adopting]);
|
|
114
|
+
return failureOf(adopting);
|
|
115
|
+
});
|
|
116
|
+
return failed === null;
|
|
117
|
+
}
|
|
118
|
+
async function adoptedMove(runtime, room, partner, local, submitted, accepted) {
|
|
119
|
+
const { store, socket } = runtime;
|
|
120
|
+
const other = socket.rooms.discovered(partner);
|
|
121
|
+
const failed = await store.exclusive(async () => {
|
|
122
|
+
const left = await acceptance(runtime, room, local, submitted, accepted);
|
|
123
|
+
const arriving = (await store.replica(partner))?.queue.find((batch) => batch.id === submitted.id);
|
|
124
|
+
const arrived = other === undefined || arriving === undefined || accepted.destination === undefined
|
|
125
|
+
? null
|
|
126
|
+
: await acceptance(runtime, other, local, arriving, {
|
|
127
|
+
kind: 'accepted',
|
|
128
|
+
...accepted.destination,
|
|
129
|
+
});
|
|
130
|
+
await adoptedTogether(runtime, local, [left, arrived]);
|
|
131
|
+
return failureOf(left);
|
|
132
|
+
});
|
|
133
|
+
submitLater(runtime, partner);
|
|
134
|
+
return failed === null;
|
|
135
|
+
}
|
|
136
|
+
async function behindIn({ store }, locator, batch) {
|
|
137
|
+
const local = await store.open();
|
|
138
|
+
const [order, { room }] = await Promise.all([
|
|
139
|
+
local.order(locator),
|
|
140
|
+
local.pending(locator, batch.id),
|
|
141
|
+
]);
|
|
142
|
+
return room ? order.indexOf(batch.id) > 0 : order.length > 0;
|
|
143
|
+
}
|
|
144
|
+
async function unpaired(local, skipped) {
|
|
145
|
+
const { queued, moving } = await local.moving();
|
|
146
|
+
for (const { locator, batch, state } of moving) {
|
|
147
|
+
const partner = partnerOf(batch, locator);
|
|
148
|
+
if (partner === null || skipped.has(pendingKey(locator, batch.id)))
|
|
149
|
+
continue;
|
|
150
|
+
if (queued.get(partner)?.includes(batch.id) === true)
|
|
151
|
+
continue;
|
|
152
|
+
if (!leavingIn(batch, locator) || withdrawable(new Map([[batch.id, state]]))(batch)) {
|
|
153
|
+
return { locator, batch };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
export async function unpair(runtime, local) {
|
|
159
|
+
const { store, socket } = runtime;
|
|
160
|
+
const handled = new Set();
|
|
161
|
+
for (let held = await unpaired(local, handled); held !== null && socket.continuing(); held = await unpaired(local, handled)) {
|
|
162
|
+
const { locator, batch } = held;
|
|
163
|
+
handled.add(pendingKey(locator, batch.id));
|
|
164
|
+
store.changed(await together(runtime, local, [await unpairing(runtime, local, locator, [batch])]));
|
|
165
|
+
}
|
|
166
|
+
if (handled.size === 0)
|
|
167
|
+
return;
|
|
168
|
+
statusShown(runtime);
|
|
169
|
+
}
|
|
170
|
+
async function submitRoom(runtime, room, local, authorized, progress, signal) {
|
|
171
|
+
const { store, socket, journal, advanced, withhold } = runtime;
|
|
172
|
+
while (socket.continuing() &&
|
|
173
|
+
socket.session.now().authorization !== undefined &&
|
|
174
|
+
!signal.aborted) {
|
|
175
|
+
const headId = (await local.order(room.locator)).find((id) => store.landed.of(room.locator, id) === undefined);
|
|
176
|
+
if (headId === undefined)
|
|
177
|
+
return 'done';
|
|
178
|
+
const [head, pending] = await Promise.all([
|
|
179
|
+
local.batch(room.locator, headId),
|
|
180
|
+
local.pending(room.locator, headId),
|
|
181
|
+
]);
|
|
182
|
+
if (head === null || !pending.room)
|
|
183
|
+
return 'done';
|
|
184
|
+
const { state } = pending;
|
|
185
|
+
const partner = partnerOf(head, room.locator);
|
|
186
|
+
if (partner !== null && !leavingIn(head, room.locator)) {
|
|
187
|
+
submitLater(runtime, partner);
|
|
188
|
+
return 'done';
|
|
189
|
+
}
|
|
190
|
+
if (partner !== null && (await behindIn(runtime, partner, head))) {
|
|
191
|
+
progress.complete = false;
|
|
192
|
+
return 'done';
|
|
193
|
+
}
|
|
194
|
+
const { submission, lost: earlier } = state ?? {
|
|
195
|
+
submission: { state: 'waiting' },
|
|
196
|
+
lost: false,
|
|
197
|
+
};
|
|
198
|
+
if (submission.state === 'reset' && Date.now() < Date.parse(submission.reset)) {
|
|
199
|
+
progress.complete = false;
|
|
200
|
+
return { at: Date.parse(submission.reset) };
|
|
201
|
+
}
|
|
202
|
+
if (socket.writesHeld()) {
|
|
203
|
+
progress.complete = false;
|
|
204
|
+
journal.record(`submission ${room.locator} ${head.id} held`);
|
|
205
|
+
return 'done';
|
|
206
|
+
}
|
|
207
|
+
const lost = earlier || submission.state === 'submitted';
|
|
208
|
+
let result;
|
|
209
|
+
journal.record(`submission ${room.locator} ${head.id}`);
|
|
210
|
+
await store.exclusive(() => mark(runtime, local, room.locator, head, { state: 'submitted' }, lost));
|
|
211
|
+
if (socket.session.now().paused || store.fences.has(room.locator))
|
|
212
|
+
return 'done';
|
|
213
|
+
if (signal.aborted || socket.writesHeld()) {
|
|
214
|
+
await store.exclusive(() => mark(runtime, local, room.locator, head, submission, earlier));
|
|
215
|
+
if (signal.aborted)
|
|
216
|
+
return 'done';
|
|
217
|
+
progress.complete = false;
|
|
218
|
+
journal.record(`submission ${room.locator} ${head.id} held`);
|
|
219
|
+
return 'done';
|
|
220
|
+
}
|
|
221
|
+
const opensBefore = socket.session.now().openSignals;
|
|
222
|
+
const answeredHere = socket.awaitingAnswer(room.locator);
|
|
223
|
+
const answeredThere = partner === null ? () => { } : socket.awaitingAnswer(partner);
|
|
224
|
+
const answered = () => {
|
|
225
|
+
answeredHere();
|
|
226
|
+
answeredThere();
|
|
227
|
+
};
|
|
228
|
+
try {
|
|
229
|
+
result = await socket.mutate(authorized, {
|
|
230
|
+
locator: room.locator,
|
|
231
|
+
changeBatch: head,
|
|
232
|
+
file: batchFile(store, head),
|
|
233
|
+
...(state?.upload === undefined ? {} : { upload: state.upload }),
|
|
234
|
+
}, (upload) => store.exclusive(() => keepUpload(runtime, local, room.locator, head.id, upload)));
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
answered();
|
|
238
|
+
progress.complete = false;
|
|
239
|
+
if (socket.continuing())
|
|
240
|
+
progress.reachable = false;
|
|
241
|
+
return 'again';
|
|
242
|
+
}
|
|
243
|
+
if (signal.aborted) {
|
|
244
|
+
answered();
|
|
245
|
+
return 'done';
|
|
246
|
+
}
|
|
247
|
+
if (result.kind !== 'accepted' || !socket.continuing())
|
|
248
|
+
answered();
|
|
249
|
+
if (!socket.continuing())
|
|
250
|
+
return 'done';
|
|
251
|
+
if (result.kind === 'transport-uncertainty') {
|
|
252
|
+
progress.complete = false;
|
|
253
|
+
progress.reachable = false;
|
|
254
|
+
return 'again';
|
|
255
|
+
}
|
|
256
|
+
if (result.kind === 'room-not-readable') {
|
|
257
|
+
progress.complete = false;
|
|
258
|
+
roomUnreadable(runtime, socket.rooms.discovered(result.locator) ?? room);
|
|
259
|
+
return 'done';
|
|
260
|
+
}
|
|
261
|
+
if (result.kind === 'revoked-authorization') {
|
|
262
|
+
await refuse(runtime, 'revoked-authorization');
|
|
263
|
+
return 'done';
|
|
264
|
+
}
|
|
265
|
+
if (result.kind === 'scoped-refusal') {
|
|
266
|
+
await runtime.scoped(result, room, local);
|
|
267
|
+
progress.complete = false;
|
|
268
|
+
return 'done';
|
|
269
|
+
}
|
|
270
|
+
if (result.kind === 'write-halted') {
|
|
271
|
+
journal.record(`outcome ${room.locator} ${head.id} write-halted`);
|
|
272
|
+
await store.exclusive(() => mark(runtime, local, room.locator, head, { state: 'waiting' }, lost));
|
|
273
|
+
if (!socket.haltedSince(opensBefore))
|
|
274
|
+
continue;
|
|
275
|
+
progress.complete = false;
|
|
276
|
+
return 'done';
|
|
277
|
+
}
|
|
278
|
+
const other = partner === null ? undefined : socket.rooms.discovered(partner);
|
|
279
|
+
if (result.kind === 'conflicted' ||
|
|
280
|
+
result.kind === 'rejected' ||
|
|
281
|
+
result.kind === 'retryable-refusal') {
|
|
282
|
+
journal.record(`outcome ${room.locator} ${head.id} ${result.kind}` +
|
|
283
|
+
(result.kind === 'conflicted' && result.roomVersion !== undefined
|
|
284
|
+
? ` ${result.roomVersion}`
|
|
285
|
+
: ''));
|
|
286
|
+
journal.record(`refusal ${result.kind} ${result.code}`);
|
|
287
|
+
}
|
|
288
|
+
if (result.kind === 'retryable-refusal') {
|
|
289
|
+
const reset = result.reset;
|
|
290
|
+
progress.complete = false;
|
|
291
|
+
await store.exclusive(() => mark(runtime, local, room.locator, head, reset === undefined ? { state: 'waiting' } : { state: 'reset', reset }, lost));
|
|
292
|
+
return reset === undefined ? 'again' : { at: Date.parse(reset) };
|
|
293
|
+
}
|
|
294
|
+
if (result.kind === 'conflicted' || result.kind === 'rejected') {
|
|
295
|
+
const left = leaving(head, result);
|
|
296
|
+
const refreshed = async () => ({
|
|
297
|
+
there: other === undefined ? null : await advanced(other, local, authorized),
|
|
298
|
+
here: await advanced(room, local, authorized),
|
|
299
|
+
});
|
|
300
|
+
const judged = result.kind === 'conflicted' && other !== undefined ? await refreshed() : null;
|
|
301
|
+
if (judged !== null && (judged.there !== null || judged.here !== null)) {
|
|
302
|
+
await store.exclusive(() => mark(runtime, local, room.locator, head, { state: 'waiting' }, lost));
|
|
303
|
+
if (other !== undefined && judged.there !== null) {
|
|
304
|
+
await withhold(judged.there, other, local, progress);
|
|
305
|
+
}
|
|
306
|
+
if (judged.here !== null)
|
|
307
|
+
await withhold(judged.here, room, local, progress);
|
|
308
|
+
return 'done';
|
|
309
|
+
}
|
|
310
|
+
await store.exclusive(async () => {
|
|
311
|
+
if (!socket.continuing())
|
|
312
|
+
return;
|
|
313
|
+
const work = await store.work(room.locator);
|
|
314
|
+
const current = work.replica;
|
|
315
|
+
if (current === undefined || !current.queue.some((batch) => batch.id === head.id)) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const confirmedLayer = await sliceAt(store, current.record, 'confirmed', [head]);
|
|
319
|
+
const held = result.kind === 'conflicted' &&
|
|
320
|
+
(await landedWhole(store, room.locator, head, confirmedLayer, result.affected));
|
|
321
|
+
if (held && partner === null && !landed(head, confirmedLayer)) {
|
|
322
|
+
store.landed.hold(room.locator, head.id, Object.fromEntries([...touchedBy([head])].map((path) => [path, confirmedLayer.revisions[path]])));
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
store.changed(await settle(runtime, local, room.locator, work, current.record, current.queue.filter((batch) => batch.id !== head.id), { leaving: [held ? { ...left, returned: null } : left] }));
|
|
326
|
+
await unpair(runtime, local);
|
|
327
|
+
statusShown(runtime);
|
|
328
|
+
});
|
|
329
|
+
const { there, here } = judged ?? (await refreshed());
|
|
330
|
+
if (other !== undefined && there !== null)
|
|
331
|
+
await withhold(there, other, local, progress);
|
|
332
|
+
if (here !== null) {
|
|
333
|
+
await withhold(here, room, local, progress);
|
|
334
|
+
return 'done';
|
|
335
|
+
}
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
const kept = await (partner === null
|
|
339
|
+
? adopted(runtime, room, local, head, result)
|
|
340
|
+
: adoptedMove(runtime, room, partner, local, head, result)).finally(answered);
|
|
341
|
+
if (!kept) {
|
|
342
|
+
progress.complete = false;
|
|
343
|
+
return 'done';
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return 'done';
|
|
347
|
+
}
|
|
348
|
+
export function submitLater(runtime, locator) {
|
|
349
|
+
if (runtime.localSaves)
|
|
350
|
+
return;
|
|
351
|
+
void runtime.recovery.attempt(`submit ${locator}`, (signal) => submitPass(runtime, locator, signal));
|
|
352
|
+
}
|
|
353
|
+
async function submitPass(runtime, locator, signal) {
|
|
354
|
+
const { store, socket } = runtime;
|
|
355
|
+
const room = socket.rooms.discovered(locator);
|
|
356
|
+
if (!socket.continuing() || socket.stopping() || room === undefined) {
|
|
357
|
+
return 'done';
|
|
358
|
+
}
|
|
359
|
+
const progress = { complete: true, reachable: true };
|
|
360
|
+
let next;
|
|
361
|
+
try {
|
|
362
|
+
await socket.authorize();
|
|
363
|
+
const { authorization } = socket.session.now();
|
|
364
|
+
if (authorization === undefined)
|
|
365
|
+
return 'done';
|
|
366
|
+
next = await submitRoom(runtime, room, await store.open(), authorization, progress, signal);
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
progress.reachable = false;
|
|
370
|
+
next = 'again';
|
|
371
|
+
}
|
|
372
|
+
if (signal.aborted)
|
|
373
|
+
return 'done';
|
|
374
|
+
await rest(runtime, progress);
|
|
375
|
+
return next === 'again' && !socket.isOpen() ? 'done' : next;
|
|
376
|
+
}
|
|
377
|
+
export async function submitAll(runtime) {
|
|
378
|
+
const { store } = runtime;
|
|
379
|
+
if (runtime.localSaves)
|
|
380
|
+
return;
|
|
381
|
+
for (const locator of await (await store.open()).queued()) {
|
|
382
|
+
if (!store.fences.has(locator))
|
|
383
|
+
submitLater(runtime, locator);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ConversationHistoryRequest } from './adapter.js';
|
|
2
|
+
import { type CallResult, type HistoryAnswer, type Resolution } from './outcome.js';
|
|
3
|
+
import type { Attempted } from './recovery.js';
|
|
4
|
+
import type { Runtime } from './runtime.js';
|
|
5
|
+
export type HistoryQuery = {
|
|
6
|
+
revision?: string;
|
|
7
|
+
pageToken?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function readHistory(runtime: Runtime, locator: string, path: string, query?: HistoryQuery): Promise<HistoryAnswer>;
|
|
10
|
+
export declare function located(runtime: Runtime, room: string, path: string, destination: string): Promise<{
|
|
11
|
+
room: string;
|
|
12
|
+
path: string;
|
|
13
|
+
} | null>;
|
|
14
|
+
export declare function resolveReference(runtime: Runtime, room: string, path: string, destination: string): Promise<Resolution>;
|
|
15
|
+
export declare function invokeAction(runtime: Runtime, name: string, input: unknown, dispatching?: () => Promise<void>): Promise<CallResult>;
|
|
16
|
+
export declare function readConversationHistory(runtime: Runtime, request: ConversationHistoryRequest): Promise<CallResult>;
|
|
17
|
+
export declare function called(runtime: Runtime, name: string, input: unknown): Promise<CallResult>;
|
|
18
|
+
export declare function resendCalls(runtime: Runtime, signal: AbortSignal): Promise<Attempted>;
|
|
19
|
+
export declare function resendLater(runtime: Runtime): void;
|
|
20
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAK/D,OAAO,EAUL,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,UAAU,EAChB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAOF,wBAAsB,WAAW,CAC/B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,KAAK,GAAE,YAAiB,GACvB,OAAO,CAAC,aAAa,CAAC,CAqCxB;AAED,wBAAsB,OAAO,CAC3B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAShD;AAED,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,CAAC,CAuBrB;AAwBD,wBAAsB,YAAY,CAChC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAChC,OAAO,CAAC,UAAU,CAAC,CA6BrB;AAED,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,UAAU,CAAC,CAiBrB;AAuCD,wBAAsB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAKhG;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAiB3F;AAiBD,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,QAG3C"}
|