@agentshouse/mdruntime 0.1.0-c6bf34fa9e444 → 0.1.0-c6d3d5d8beeb0
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 +21 -19
- package/dist/acceptance.d.ts +0 -3
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +105 -166
- package/dist/act-lanes.d.ts +30 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +225 -0
- package/dist/actions.d.ts +8 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +180 -85
- package/dist/adapter.d.ts +222 -73
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +0 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +2 -7
- package/dist/{binary.d.ts → attachment.d.ts} +8 -4
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +15 -0
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +345 -0
- package/dist/bootstrap.d.ts +1 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +6 -18
- package/dist/chain.d.ts +1 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +5 -2
- package/dist/change-set.d.ts +4 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -0
- package/dist/change.d.ts +6 -2
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +7 -2
- package/dist/chat-types.d.ts +0 -2
- package/dist/chat-types.d.ts.map +1 -1
- package/dist/chat-types.js +2 -4
- package/dist/client.d.ts +30 -23
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +55 -68
- package/dist/collection.d.ts +27 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +34 -10
- package/dist/column.d.ts +5 -0
- package/dist/column.d.ts.map +1 -0
- package/dist/column.js +9 -0
- package/dist/compile.d.ts +4 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +101 -63
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +45 -28
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +150 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +260 -0
- package/dist/conversation-row.d.ts +23 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +39 -4
- package/dist/conversation.d.ts +67 -49
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +993 -1032
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +47 -47
- package/dist/download.d.ts +6 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +42 -0
- package/dist/durability.d.ts +5 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +26 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +126 -36
- package/dist/expectation.d.ts +26 -13
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +72 -19
- package/dist/failure.d.ts +3 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +8 -0
- package/dist/figures.d.ts +2 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +8 -6
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -2
- package/dist/host.d.ts +24 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +108 -32
- package/dist/house-query.d.ts +24 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +102 -0
- package/dist/identity.d.ts +1 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +1 -1
- package/dist/index.d.ts +30 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -8
- package/dist/install.d.ts +10 -6
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +93 -116
- package/dist/lifecycle.d.ts +2 -2
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +81 -56
- package/dist/linked-file.d.ts +7 -0
- package/dist/linked-file.d.ts.map +1 -0
- package/dist/linked-file.js +16 -0
- package/dist/listing.d.ts +29 -22
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +71 -78
- package/dist/live.d.ts +19 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +97 -39
- package/dist/loaded.d.ts +7 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +46 -0
- package/dist/locks.d.ts +2 -4
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +12 -39
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +11 -23
- package/dist/media.d.ts +20 -4
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +184 -37
- package/dist/memory.d.ts +10 -4
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +103 -40
- package/dist/messages.d.ts +21 -6
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +54 -42
- package/dist/modal.d.ts +2 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +11 -0
- package/dist/model.d.ts +10 -8
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -5
- package/dist/models.d.ts +4 -8
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +97 -137
- package/dist/name.d.ts +0 -1
- package/dist/name.d.ts.map +1 -1
- package/dist/name.js +3 -7
- package/dist/observation.d.ts +29 -12
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +217 -85
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/opened.d.ts +6 -6
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +7 -7
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +26 -11
- package/dist/outcome.d.ts +33 -13
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +36 -6
- package/dist/overlay.d.ts +23 -8
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +132 -48
- package/dist/page-metadata.d.ts +8 -0
- package/dist/page-metadata.d.ts.map +1 -0
- package/dist/page-metadata.js +19 -0
- package/dist/parts.d.ts +6 -58
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +28 -110
- 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 +33 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +210 -92
- package/dist/presence.d.ts +58 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +231 -0
- package/dist/queries.d.ts +2 -2
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +138 -80
- package/dist/query.d.ts +2 -3
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +3 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +6 -7
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +482 -0
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +200 -40
- package/dist/react.d.ts +21 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +33 -1
- package/dist/readiness.d.ts +23 -5
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +18 -10
- package/dist/reads.d.ts +5 -2
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +64 -11
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +31 -8
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +6 -6
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +5 -6
- package/dist/replica.d.ts +6 -16
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +20 -21
- package/dist/retried.d.ts +30 -0
- package/dist/retried.d.ts.map +1 -0
- package/dist/retried.js +72 -0
- package/dist/room-draft.d.ts +32 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +282 -72
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +29 -23
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +47 -0
- package/dist/rows.d.ts +11 -3
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +28 -15
- package/dist/run-tables.d.ts +25 -0
- package/dist/run-tables.d.ts.map +1 -0
- package/dist/run-tables.js +98 -0
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runs.d.ts +27 -0
- package/dist/runs.d.ts.map +1 -0
- package/dist/runs.js +92 -0
- package/dist/runtime.d.ts +16 -21
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +43 -86
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +337 -232
- package/dist/saves.d.ts +9 -45
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +208 -748
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +4 -5
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- 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 +10 -6
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +108 -75
- package/dist/socket/lanes.d.ts +12 -4
- package/dist/socket/lanes.d.ts.map +1 -1
- package/dist/socket/lanes.js +34 -8
- package/dist/socket/session.d.ts +4 -2
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket/session.js +3 -0
- package/dist/socket.d.ts +7 -7
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +13 -16
- package/dist/source.d.ts +42 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +81 -13
- package/dist/store/installs.d.ts +2 -2
- package/dist/store/installs.d.ts.map +1 -1
- package/dist/store/installs.js +10 -4
- package/dist/store/readiness.d.ts +5 -4
- package/dist/store/readiness.d.ts.map +1 -1
- package/dist/store/readiness.js +28 -12
- package/dist/store/records.d.ts +33 -11
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +94 -28
- package/dist/store/rooms-shown.d.ts +8 -0
- package/dist/store/rooms-shown.d.ts.map +1 -0
- package/dist/store/rooms-shown.js +13 -0
- package/dist/store/space.d.ts +1 -1
- package/dist/store/space.d.ts.map +1 -1
- package/dist/store/space.js +0 -2
- package/dist/store/watchers.js +1 -2
- package/dist/store.d.ts +26 -16
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +50 -18
- package/dist/stored.d.ts +42 -17
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +236 -66
- package/dist/surface.d.ts +21 -9
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +74 -38
- package/dist/sync.d.ts +4 -3
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +136 -110
- package/dist/tables.d.ts +43 -58
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +114 -334
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +8 -9
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +51 -11
- package/dist/wire.d.ts +72 -12
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +31 -14
- package/package.json +4 -3
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
- package/dist/job.d.ts +0 -33
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -54
- package/dist/log.d.ts +0 -6
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/socket/rooms.d.ts +0 -43
- package/dist/socket/rooms.d.ts.map +0 -1
- package/dist/socket/rooms.js +0 -90
- package/dist/store/fences.d.ts +0 -16
- package/dist/store/fences.d.ts.map +0 -1
- package/dist/store/fences.js +0 -26
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { expectedList } from './expectation.js';
|
|
2
|
+
import { changeBatchIdentity } from './identity.js';
|
|
3
|
+
const IDLE = { busy: false, drawn: false, ended: null };
|
|
4
|
+
export function acting(rules) {
|
|
5
|
+
const { store, uncertain, ending, settles } = rules;
|
|
6
|
+
const mint = rules.mint ?? (() => changeBatchIdentity());
|
|
7
|
+
const identities = new Map();
|
|
8
|
+
const waiting = new Map();
|
|
9
|
+
const settling = new Map();
|
|
10
|
+
const blobs = new WeakMap();
|
|
11
|
+
let counted = 0;
|
|
12
|
+
let touches = 0;
|
|
13
|
+
const requestOf = (name, input) => {
|
|
14
|
+
const carried = [];
|
|
15
|
+
const json = JSON.stringify(input, (_key, value) => {
|
|
16
|
+
if (!(value instanceof Blob))
|
|
17
|
+
return value;
|
|
18
|
+
let one = blobs.get(value);
|
|
19
|
+
if (one === undefined) {
|
|
20
|
+
counted += 1;
|
|
21
|
+
one = counted;
|
|
22
|
+
blobs.set(value, one);
|
|
23
|
+
}
|
|
24
|
+
carried.push(one);
|
|
25
|
+
return null;
|
|
26
|
+
});
|
|
27
|
+
return `${name}\u0000${json}\u0000${carried.join(',')}`;
|
|
28
|
+
};
|
|
29
|
+
const identityOf = (request) => {
|
|
30
|
+
const held = identities.get(request);
|
|
31
|
+
if (held !== undefined)
|
|
32
|
+
return held;
|
|
33
|
+
const fresh = { operation: mint(), touched: 0, flying: 0 };
|
|
34
|
+
identities.set(request, fresh);
|
|
35
|
+
return fresh;
|
|
36
|
+
};
|
|
37
|
+
const settled = (act, ended, calls) => {
|
|
38
|
+
const released = new Map();
|
|
39
|
+
for (const { request, identity, ended: answered } of calls) {
|
|
40
|
+
const heard = answered === 'accepted' || answered === 'refused';
|
|
41
|
+
if (ended === 'accepted' && heard)
|
|
42
|
+
released.set(request, identity.touched);
|
|
43
|
+
else {
|
|
44
|
+
touches += 1;
|
|
45
|
+
identity.touched = touches;
|
|
46
|
+
identities.set(request, identity);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (ended === 'refused' || ended === 'unsent')
|
|
50
|
+
store.drop(act);
|
|
51
|
+
for (const { request, ended: answered } of calls) {
|
|
52
|
+
const earlier = waiting.get(request);
|
|
53
|
+
if (answered === 'unsent' && earlier !== undefined)
|
|
54
|
+
continue;
|
|
55
|
+
if (earlier !== undefined && earlier !== act)
|
|
56
|
+
store.drop(earlier);
|
|
57
|
+
if (ended === 'unanswered')
|
|
58
|
+
waiting.set(request, act);
|
|
59
|
+
else
|
|
60
|
+
waiting.delete(request);
|
|
61
|
+
}
|
|
62
|
+
if (ended === 'accepted' || calls.some((one) => one.ended === 'accepted'))
|
|
63
|
+
rules.acted?.();
|
|
64
|
+
return released;
|
|
65
|
+
};
|
|
66
|
+
const release = (released) => {
|
|
67
|
+
for (const [request, touched] of released) {
|
|
68
|
+
const held = identities.get(request);
|
|
69
|
+
if (held !== undefined && held.touched === touched && held.flying === 0) {
|
|
70
|
+
identities.delete(request);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
open() {
|
|
76
|
+
const listeners = new Set();
|
|
77
|
+
const releasing = new Map();
|
|
78
|
+
let tail = Promise.resolve();
|
|
79
|
+
let pressed = 0;
|
|
80
|
+
let drawing = 0;
|
|
81
|
+
let ended = null;
|
|
82
|
+
let held = null;
|
|
83
|
+
let presses = 0;
|
|
84
|
+
let shown = IDLE;
|
|
85
|
+
const show = () => {
|
|
86
|
+
const busy = pressed > 0;
|
|
87
|
+
const drawn = drawing > 0;
|
|
88
|
+
if (shown.busy === busy && shown.drawn === drawn && shown.ended === ended)
|
|
89
|
+
return;
|
|
90
|
+
shown = { busy, drawn, ended };
|
|
91
|
+
for (const listener of listeners)
|
|
92
|
+
listener();
|
|
93
|
+
};
|
|
94
|
+
const awaiting = (outcome, operations, heard, again) => new Promise((resolve) => {
|
|
95
|
+
const forgotten = () => {
|
|
96
|
+
for (const operation of operations)
|
|
97
|
+
if (settling.get(operation) === record)
|
|
98
|
+
settling.delete(operation);
|
|
99
|
+
};
|
|
100
|
+
const record = {
|
|
101
|
+
supersede() {
|
|
102
|
+
if (held !== record)
|
|
103
|
+
return;
|
|
104
|
+
held = null;
|
|
105
|
+
forgotten();
|
|
106
|
+
resolve(outcome);
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
held = record;
|
|
110
|
+
for (const operation of operations)
|
|
111
|
+
settling.set(operation, record);
|
|
112
|
+
const answers = operations.map((operation) => heard(operation).then((answered) => {
|
|
113
|
+
if (!answered)
|
|
114
|
+
record.supersede();
|
|
115
|
+
return answered;
|
|
116
|
+
}));
|
|
117
|
+
void Promise.all(answers).then(() => {
|
|
118
|
+
if (held !== record)
|
|
119
|
+
return;
|
|
120
|
+
held = null;
|
|
121
|
+
forgotten();
|
|
122
|
+
resolve(again());
|
|
123
|
+
}, () => record.supersede());
|
|
124
|
+
});
|
|
125
|
+
const attempt = (steps, expected, press) => {
|
|
126
|
+
const act = store.begin();
|
|
127
|
+
let drew = false;
|
|
128
|
+
const expect = (more) => {
|
|
129
|
+
if (expectedList(more).length === 0)
|
|
130
|
+
return;
|
|
131
|
+
store.expect(act, more);
|
|
132
|
+
if (drew)
|
|
133
|
+
return;
|
|
134
|
+
drew = true;
|
|
135
|
+
drawing += 1;
|
|
136
|
+
show();
|
|
137
|
+
};
|
|
138
|
+
pressed += 1;
|
|
139
|
+
expect(expected);
|
|
140
|
+
show();
|
|
141
|
+
const calls = [];
|
|
142
|
+
const send = Object.assign(async (name, input, sending) => {
|
|
143
|
+
const request = requestOf(name, input);
|
|
144
|
+
const identity = identityOf(request);
|
|
145
|
+
settling.get(identity.operation)?.supersede();
|
|
146
|
+
const called = { request, identity, ended: null };
|
|
147
|
+
calls.push(called);
|
|
148
|
+
touches += 1;
|
|
149
|
+
identity.touched = touches;
|
|
150
|
+
identity.flying += 1;
|
|
151
|
+
let outcome;
|
|
152
|
+
try {
|
|
153
|
+
outcome = await sending(identity.operation);
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
outcome = uncertain;
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
identity.flying -= 1;
|
|
160
|
+
}
|
|
161
|
+
called.ended = ending(outcome);
|
|
162
|
+
return outcome;
|
|
163
|
+
}, { expect });
|
|
164
|
+
const end = (outcome, how) => {
|
|
165
|
+
for (const [request, touched] of settled(act, how, calls))
|
|
166
|
+
releasing.set(request, touched);
|
|
167
|
+
pressed -= 1;
|
|
168
|
+
if (drew)
|
|
169
|
+
drawing -= 1;
|
|
170
|
+
ended = outcome;
|
|
171
|
+
if (pressed === 0) {
|
|
172
|
+
release(releasing);
|
|
173
|
+
releasing.clear();
|
|
174
|
+
}
|
|
175
|
+
show();
|
|
176
|
+
};
|
|
177
|
+
const turn = tail.then(async () => {
|
|
178
|
+
ended = null;
|
|
179
|
+
show();
|
|
180
|
+
let outcome;
|
|
181
|
+
try {
|
|
182
|
+
outcome = await steps(send);
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
end(uncertain, 'unanswered');
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
const how = ending(outcome);
|
|
189
|
+
end(outcome, how);
|
|
190
|
+
return { outcome, how };
|
|
191
|
+
});
|
|
192
|
+
tail = turn.catch(() => undefined);
|
|
193
|
+
return turn.then(({ outcome, how }) => {
|
|
194
|
+
const lost = calls.flatMap(({ identity, ended: answered }) => answered === 'unanswered' ? [identity.operation] : []);
|
|
195
|
+
if (how !== 'unanswered' || lost.length === 0 || settles === undefined)
|
|
196
|
+
return outcome;
|
|
197
|
+
if (press !== presses)
|
|
198
|
+
return outcome;
|
|
199
|
+
return awaiting(outcome, lost, settles, () => attempt(steps, expected, press));
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
const run = (steps, expected = null) => {
|
|
203
|
+
held?.supersede();
|
|
204
|
+
presses += 1;
|
|
205
|
+
return attempt(steps, expected, presses);
|
|
206
|
+
};
|
|
207
|
+
return {
|
|
208
|
+
run,
|
|
209
|
+
shown: () => shown,
|
|
210
|
+
subscribe(listener) {
|
|
211
|
+
listeners.add(listener);
|
|
212
|
+
return () => {
|
|
213
|
+
listeners.delete(listener);
|
|
214
|
+
};
|
|
215
|
+
},
|
|
216
|
+
forget() {
|
|
217
|
+
if (pressed > 0 || ended === null)
|
|
218
|
+
return;
|
|
219
|
+
ended = null;
|
|
220
|
+
show();
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ConversationHistoryRequest } from './adapter.js';
|
|
2
2
|
import { type CallResult, type HistoryAnswer, type Resolution } from './outcome.js';
|
|
3
3
|
import type { Attempted } from './recovery.js';
|
|
4
|
+
import type { Attempt } from './retried.js';
|
|
4
5
|
import type { Runtime } from './runtime.js';
|
|
5
6
|
export type HistoryQuery = {
|
|
6
7
|
revision?: string;
|
|
@@ -12,9 +13,14 @@ export declare function located(runtime: Runtime, room: string, path: string, de
|
|
|
12
13
|
path: string;
|
|
13
14
|
} | null>;
|
|
14
15
|
export declare function resolveReference(runtime: Runtime, room: string, path: string, destination: string): Promise<Resolution>;
|
|
15
|
-
export
|
|
16
|
+
export type Invoked = {
|
|
17
|
+
readonly dispatching?: () => Promise<void>;
|
|
18
|
+
readonly attempt?: Attempt;
|
|
19
|
+
};
|
|
20
|
+
export declare function invokeAction(runtime: Runtime, name: string, input: unknown, { dispatching, attempt }?: Invoked): Promise<CallResult>;
|
|
16
21
|
export declare function readConversationHistory(runtime: Runtime, request: ConversationHistoryRequest): Promise<CallResult>;
|
|
17
|
-
export declare function called(runtime: Runtime, name: string, input: unknown): Promise<CallResult>;
|
|
22
|
+
export declare function called(runtime: Runtime, name: string, input: unknown, attempt?: Attempt): Promise<CallResult>;
|
|
23
|
+
export declare function answeredCall(runtime: Runtime, operation: string): Promise<boolean>;
|
|
18
24
|
export declare function resendCalls(runtime: Runtime, signal: AbortSignal): Promise<Attempted>;
|
|
19
25
|
export declare function resendLater(runtime: Runtime): void;
|
|
20
26
|
//# sourceMappingURL=actions.d.ts.map
|
package/dist/actions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAM3E,OAAO,EAWL,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;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C,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,CA+BxB;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,CAOhD;AAED,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,CAAC,CAsBrB;AAgED,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,wBAAsB,YAAY,CAChC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,EAAE,WAAW,EAAE,OAAO,EAAE,GAAE,OAAY,GACrC,OAAO,CAAC,UAAU,CAAC,CAiCrB;AAED,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,UAAU,CAAC,CAerB;AA4GD,wBAAsB,MAAM,CAC1B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC,UAAU,CAAC,CAKrB;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAaxF;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAkB3F;AAiBD,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,QAG3C"}
|
package/dist/actions.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { classifyHref, parseRoomPath, roomTarget } from '@agentshouse/mdmodel';
|
|
2
|
+
import { CATCHING_UP, holdsSubmission, resendConversations } from './conversation.js';
|
|
2
3
|
import { listingNow } from './listing.js';
|
|
3
4
|
import { locked, lockedRooms } from './locks.js';
|
|
4
5
|
import { scoped } from './models.js';
|
|
5
|
-
import { ABSENT_TARGET,
|
|
6
|
+
import { ABSENT_TARGET, failure, historyAnswer, LOCKED_UNREADABLE, lockedRoom, handedOutcome, UNANSWERED, undeclared, UNCERTAIN, UNREADABLE, } from './outcome.js';
|
|
6
7
|
import { refuse } from './refusal.js';
|
|
8
|
+
import { selectorValues } from './selector.js';
|
|
7
9
|
function operationOf(input) {
|
|
8
10
|
const operation = input?.operation_id;
|
|
9
11
|
return typeof operation === 'string' ? operation : null;
|
|
10
12
|
}
|
|
11
13
|
export async function readHistory(runtime, locator, path, query = {}) {
|
|
12
|
-
const { store, socket,
|
|
14
|
+
const { store, socket, presence } = runtime;
|
|
13
15
|
const { session } = socket;
|
|
14
16
|
if (socket.closed() || session.now().refusal !== null)
|
|
15
17
|
return UNCERTAIN;
|
|
@@ -25,13 +27,7 @@ export async function readHistory(runtime, locator, path, query = {}) {
|
|
|
25
27
|
const { closed, authorization, refusal } = session.now();
|
|
26
28
|
if (closed || authorization === undefined || refusal !== null)
|
|
27
29
|
return UNCERTAIN;
|
|
28
|
-
const since =
|
|
29
|
-
const transfer = ['transfer', 'history', locator, path];
|
|
30
|
-
if (query.revision !== undefined)
|
|
31
|
-
transfer.push(query.revision);
|
|
32
|
-
if (query.pageToken !== undefined)
|
|
33
|
-
transfer.push(query.pageToken);
|
|
34
|
-
journal.record(transfer.join(' '));
|
|
30
|
+
const since = presence.losses();
|
|
35
31
|
try {
|
|
36
32
|
const result = await socket.history(authorization, {
|
|
37
33
|
locator,
|
|
@@ -39,38 +35,36 @@ export async function readHistory(runtime, locator, path, query = {}) {
|
|
|
39
35
|
...(query.revision === undefined ? {} : { revision: query.revision }),
|
|
40
36
|
...(query.pageToken === undefined ? {} : { pageToken: query.pageToken }),
|
|
41
37
|
});
|
|
42
|
-
|
|
43
|
-
if (store.fences.since(locator, since))
|
|
38
|
+
if (presence.lostSince(locator, since))
|
|
44
39
|
return failure({ kind: 'room-not-readable', locator });
|
|
45
40
|
if (result.kind === 'scoped-refusal') {
|
|
46
41
|
const room = await store.record(result.locator);
|
|
47
42
|
if (room !== undefined)
|
|
48
|
-
await scoped(runtime, result, room,
|
|
43
|
+
await scoped(runtime, result, room.locator, room.declaration);
|
|
49
44
|
}
|
|
50
45
|
if (result.kind === 'revoked-authorization')
|
|
51
46
|
await refuse(runtime, 'revoked-authorization');
|
|
52
47
|
return historyAnswer(result);
|
|
53
48
|
}
|
|
54
49
|
catch {
|
|
55
|
-
journal.record('outcome history transport-uncertainty');
|
|
56
50
|
return UNCERTAIN;
|
|
57
51
|
}
|
|
58
52
|
}
|
|
59
53
|
export async function located(runtime, room, path, destination) {
|
|
60
|
-
const crossing = roomTarget(destination);
|
|
61
54
|
const listing = await listingNow(runtime);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
55
|
+
const named = classifyHref(path, destination, listing.get(room)?.handle);
|
|
56
|
+
if (named.kind === 'path')
|
|
57
|
+
return listing.has(room) ? { room, path: named.path } : null;
|
|
58
|
+
if (named.kind !== 'room')
|
|
59
|
+
return null;
|
|
60
|
+
const held = [...listing.values()].find((listed) => listed.handle === named.handle);
|
|
61
|
+
return held === undefined ? null : { room: held.locator, path: named.path };
|
|
68
62
|
}
|
|
69
63
|
export async function resolveReference(runtime, room, path, destination) {
|
|
70
64
|
const { store } = runtime;
|
|
71
|
-
|
|
65
|
+
const kind = classifyHref(path, destination).kind;
|
|
66
|
+
if (kind !== 'path' && kind !== 'room')
|
|
72
67
|
return ABSENT_TARGET;
|
|
73
|
-
}
|
|
74
68
|
const at = await located(runtime, room, path, destination);
|
|
75
69
|
if (at === null)
|
|
76
70
|
return UNREADABLE;
|
|
@@ -93,8 +87,16 @@ export async function resolveReference(runtime, room, path, destination) {
|
|
|
93
87
|
? { kind: 'deleted', ...at, revision: last }
|
|
94
88
|
: { kind: 'document', ...at };
|
|
95
89
|
}
|
|
96
|
-
async function
|
|
97
|
-
|
|
90
|
+
async function declaredActions({ store, socket }) {
|
|
91
|
+
const { unstored } = socket.session.now();
|
|
92
|
+
if (unstored !== null)
|
|
93
|
+
return unstored.capabilities;
|
|
94
|
+
if (!store.needed())
|
|
95
|
+
return [];
|
|
96
|
+
return (await (await store.open()).facts()).capabilities;
|
|
97
|
+
}
|
|
98
|
+
async function declaredAction(runtime, name) {
|
|
99
|
+
for (const capability of await declaredActions(runtime)) {
|
|
98
100
|
for (const action of capability.actions ?? []) {
|
|
99
101
|
if (action.name === name)
|
|
100
102
|
return action;
|
|
@@ -102,69 +104,95 @@ async function declaredAction({ store }, name) {
|
|
|
102
104
|
}
|
|
103
105
|
return undefined;
|
|
104
106
|
}
|
|
107
|
+
async function declaration(runtime, name) {
|
|
108
|
+
const { socket } = runtime;
|
|
109
|
+
const declared = await declaredAction(runtime, name);
|
|
110
|
+
if (declared !== undefined || socket.streamed || socket.session.now().roomsNamed)
|
|
111
|
+
return declared;
|
|
112
|
+
await runtime.discover();
|
|
113
|
+
return declaredAction(runtime, name);
|
|
114
|
+
}
|
|
115
|
+
function strings(values) {
|
|
116
|
+
return values.filter((value) => typeof value === 'string');
|
|
117
|
+
}
|
|
118
|
+
const ROOM_TOP = /^\/rooms\/([^/]+)\/?$/u;
|
|
119
|
+
const FOLDER_END = /\/$/u;
|
|
120
|
+
function namedRoom(path) {
|
|
121
|
+
return (parseRoomPath(path.replace(FOLDER_END, ''))?.handle ??
|
|
122
|
+
roomTarget(path)?.handle ??
|
|
123
|
+
ROOM_TOP.exec(path)?.[1] ??
|
|
124
|
+
null);
|
|
125
|
+
}
|
|
105
126
|
async function calledRooms(runtime, name, input) {
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
127
|
+
const declared = await declaration(runtime, name);
|
|
128
|
+
if (declared === undefined || input === null || typeof input !== 'object')
|
|
108
129
|
return [];
|
|
109
|
-
const named =
|
|
110
|
-
|
|
130
|
+
const named = declared.room === undefined ? [] : strings(selectorValues(input, declared.room));
|
|
131
|
+
const handles = strings((declared.roomPaths ?? []).flatMap((selector) => selectorValues(input, selector))).flatMap((path) => namedRoom(path) ?? []);
|
|
132
|
+
if (handles.length === 0)
|
|
133
|
+
return named;
|
|
134
|
+
const listing = await listingNow(runtime);
|
|
135
|
+
return [
|
|
136
|
+
...named,
|
|
137
|
+
...[...listing.values()]
|
|
138
|
+
.filter((listed) => handles.includes(listed.handle) || handles.includes(listed.locator))
|
|
139
|
+
.map((listed) => listed.locator),
|
|
140
|
+
];
|
|
111
141
|
}
|
|
112
|
-
export async function invokeAction(runtime, name, input, dispatching) {
|
|
113
|
-
const { store, socket,
|
|
142
|
+
export async function invokeAction(runtime, name, input, { dispatching, attempt } = {}) {
|
|
143
|
+
const { store, socket, retries } = runtime;
|
|
114
144
|
const { session } = socket;
|
|
115
145
|
await socket.ready;
|
|
116
|
-
if (socket.closed() || session.now().refusal !== null)
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
|
|
146
|
+
if (socket.closed() || session.now().refusal !== null) {
|
|
147
|
+
return handedOutcome(retries, attempt, UNANSWERED);
|
|
148
|
+
}
|
|
149
|
+
if ((await declaredAction(runtime, name)) === undefined) {
|
|
150
|
+
return session.now().roomsNamed
|
|
151
|
+
? undeclared(name)
|
|
152
|
+
: handedOutcome(retries, attempt, UNANSWERED);
|
|
153
|
+
}
|
|
120
154
|
try {
|
|
121
155
|
await socket.authorize();
|
|
122
156
|
}
|
|
123
157
|
catch {
|
|
124
|
-
return
|
|
158
|
+
return handedOutcome(retries, attempt, UNANSWERED);
|
|
125
159
|
}
|
|
126
160
|
const { closed, authorization, refusal } = session.now();
|
|
127
|
-
if (closed || authorization === undefined || refusal !== null)
|
|
128
|
-
return
|
|
161
|
+
if (closed || authorization === undefined || refusal !== null) {
|
|
162
|
+
return handedOutcome(retries, attempt, UNANSWERED);
|
|
163
|
+
}
|
|
129
164
|
await dispatching?.();
|
|
130
|
-
journal.record(`transfer action ${name}`);
|
|
131
165
|
try {
|
|
132
166
|
const result = await socket.action(authorization, { name, input });
|
|
133
167
|
if (result.kind === 'scoped-refusal') {
|
|
134
168
|
const room = await store.record(result.locator);
|
|
135
169
|
if (room !== undefined)
|
|
136
|
-
await scoped(runtime, result, room,
|
|
170
|
+
await scoped(runtime, result, room.locator, room.declaration);
|
|
137
171
|
}
|
|
138
172
|
if (result.kind === 'revoked-authorization')
|
|
139
173
|
await refuse(runtime, 'revoked-authorization');
|
|
140
|
-
|
|
141
|
-
if (result.kind === 'rejected')
|
|
142
|
-
journal.record(`refusal rejected ${result.code}`);
|
|
143
|
-
return calledResult(result);
|
|
174
|
+
return handedOutcome(retries, attempt, result);
|
|
144
175
|
}
|
|
145
|
-
catch {
|
|
146
|
-
|
|
147
|
-
return UNCERTAIN;
|
|
176
|
+
catch (error) {
|
|
177
|
+
return handedOutcome(retries, attempt, { kind: 'transport-uncertainty', failure: error });
|
|
148
178
|
}
|
|
149
179
|
}
|
|
150
180
|
export async function readConversationHistory(runtime, request) {
|
|
151
|
-
const { socket,
|
|
181
|
+
const { socket, retries } = runtime;
|
|
182
|
+
const caught = { step: 'conversations', instance: CATCHING_UP };
|
|
152
183
|
await socket.ready;
|
|
153
184
|
const stream = socket.conversations();
|
|
154
185
|
if (socket.closed() || socket.session.now().refusal !== null || stream?.history === undefined) {
|
|
155
|
-
return
|
|
186
|
+
return handedOutcome(retries, caught, UNANSWERED);
|
|
156
187
|
}
|
|
157
|
-
journal.record('transfer conversation history');
|
|
158
188
|
try {
|
|
159
189
|
const result = await stream.history(request);
|
|
160
190
|
if (result.kind === 'revoked-authorization')
|
|
161
191
|
await refuse(runtime, 'revoked-authorization');
|
|
162
|
-
|
|
163
|
-
return calledResult(result);
|
|
192
|
+
return handedOutcome(retries, caught, result);
|
|
164
193
|
}
|
|
165
|
-
catch {
|
|
166
|
-
|
|
167
|
-
return UNCERTAIN;
|
|
194
|
+
catch (error) {
|
|
195
|
+
return handedOutcome(retries, caught, { kind: 'transport-uncertainty', failure: error });
|
|
168
196
|
}
|
|
169
197
|
}
|
|
170
198
|
function unsettled(result) {
|
|
@@ -172,59 +200,126 @@ function unsettled(result) {
|
|
|
172
200
|
return false;
|
|
173
201
|
return result.retryable && (result.kind !== 'rejected' || result.reset === undefined);
|
|
174
202
|
}
|
|
175
|
-
|
|
176
|
-
|
|
203
|
+
function numberedCall(runtime, name, input, operation, dispatching) {
|
|
204
|
+
return invokeAction(runtime, name, input, {
|
|
205
|
+
dispatching,
|
|
206
|
+
attempt: { step: 'sending', instance: `action ${operation}` },
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
function keptSender(runtime, name, input, operation, resent = false) {
|
|
210
|
+
const { store, socket } = runtime;
|
|
177
211
|
const { lanes } = socket;
|
|
212
|
+
const dispatching = async () => (await store.open()).keepCall({ operation, name, input });
|
|
213
|
+
let waiting = [];
|
|
214
|
+
let last = UNCERTAIN;
|
|
215
|
+
let lost = resent;
|
|
216
|
+
const tell = (result) => {
|
|
217
|
+
last = result;
|
|
218
|
+
const told = waiting;
|
|
219
|
+
waiting = [];
|
|
220
|
+
for (const answer of told)
|
|
221
|
+
answer(result);
|
|
222
|
+
};
|
|
223
|
+
const sender = {
|
|
224
|
+
next: () => new Promise((answer) => waiting.push(answer)),
|
|
225
|
+
async send() {
|
|
226
|
+
let result;
|
|
227
|
+
try {
|
|
228
|
+
result = await numberedCall(runtime, name, input, operation, dispatching);
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
tell(last);
|
|
232
|
+
throw error;
|
|
233
|
+
}
|
|
234
|
+
if (unsettled(result))
|
|
235
|
+
lost = true;
|
|
236
|
+
else {
|
|
237
|
+
await (await store.open()).dropCall(operation);
|
|
238
|
+
lanes.settle(operation, lost);
|
|
239
|
+
}
|
|
240
|
+
tell(result);
|
|
241
|
+
return result;
|
|
242
|
+
},
|
|
243
|
+
release() {
|
|
244
|
+
lanes.sent(operation, sender);
|
|
245
|
+
tell(last);
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
lanes.sending(operation, sender);
|
|
249
|
+
return sender;
|
|
250
|
+
}
|
|
251
|
+
async function recoveredAction(runtime, name, input, attempt) {
|
|
252
|
+
const { socket, recovery } = runtime;
|
|
178
253
|
const operation = operationOf(input);
|
|
179
254
|
if (operation === null)
|
|
180
|
-
return invokeAction(runtime, name, input);
|
|
181
|
-
const
|
|
182
|
-
|
|
255
|
+
return invokeAction(runtime, name, input, { attempt });
|
|
256
|
+
const held = socket.lanes.sender(operation);
|
|
257
|
+
if (held !== undefined)
|
|
258
|
+
return held.next();
|
|
259
|
+
const sender = keptSender(runtime, name, input, operation);
|
|
260
|
+
let first;
|
|
183
261
|
try {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (!socket.isOpen())
|
|
190
|
-
return 'again';
|
|
191
|
-
result = await invokeAction(runtime, name, input, kept);
|
|
192
|
-
return unsettled(result) ? 'again' : 'done';
|
|
193
|
-
}, { again: true });
|
|
194
|
-
}
|
|
195
|
-
if (!unsettled(result))
|
|
196
|
-
await (await store.open()).dropCall(operation);
|
|
197
|
-
return result;
|
|
262
|
+
first = await sender.send();
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
sender.release();
|
|
266
|
+
throw error;
|
|
198
267
|
}
|
|
199
|
-
|
|
200
|
-
|
|
268
|
+
if (!unsettled(first)) {
|
|
269
|
+
sender.release();
|
|
270
|
+
return first;
|
|
201
271
|
}
|
|
272
|
+
void recovery
|
|
273
|
+
.attempt(`action ${operation}`, async () => {
|
|
274
|
+
if (socket.closed() || socket.session.now().refusal !== null)
|
|
275
|
+
return 'done';
|
|
276
|
+
if (!socket.isOpen())
|
|
277
|
+
return 'again';
|
|
278
|
+
return unsettled(await sender.send()) ? 'again' : 'done';
|
|
279
|
+
}, { again: true })
|
|
280
|
+
.finally(() => sender.release());
|
|
281
|
+
return first;
|
|
202
282
|
}
|
|
203
|
-
export async function called(runtime, name, input) {
|
|
283
|
+
export async function called(runtime, name, input, attempt) {
|
|
204
284
|
await runtime.socket.ready;
|
|
205
285
|
const lockedNow = await lockedRooms(runtime);
|
|
206
286
|
const room = (await calledRooms(runtime, name, input)).find((one) => lockedNow.includes(one));
|
|
207
|
-
return room === undefined ? recoveredAction(runtime, name, input) : lockedRoom(room);
|
|
287
|
+
return room === undefined ? recoveredAction(runtime, name, input, attempt) : lockedRoom(room);
|
|
208
288
|
}
|
|
209
|
-
export async function
|
|
289
|
+
export async function answeredCall(runtime, operation) {
|
|
210
290
|
const { store, socket } = runtime;
|
|
211
291
|
const { lanes } = socket;
|
|
292
|
+
const held = () => lanes.sender(operation) !== undefined || lanes.unclaimed(operation);
|
|
293
|
+
if (!held()) {
|
|
294
|
+
const calls = await (await store.open()).calls();
|
|
295
|
+
const kept = calls.some((one) => one.operation === operation) ||
|
|
296
|
+
(await holdsSubmission(runtime.conversations, operation));
|
|
297
|
+
if (!held() && !kept)
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
await lanes.settled(operation);
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
export async function resendCalls(runtime, signal) {
|
|
304
|
+
const { store, socket } = runtime;
|
|
212
305
|
if (!socket.isOpen() || socket.closed() || socket.stopping())
|
|
213
306
|
return 'done';
|
|
214
307
|
const local = await store.open();
|
|
215
308
|
for (const held of await local.calls()) {
|
|
216
|
-
if (lanes.
|
|
309
|
+
if (socket.lanes.sender(held.operation) !== undefined)
|
|
217
310
|
continue;
|
|
218
311
|
if (socket.closed() || signal.aborted)
|
|
219
312
|
return 'done';
|
|
220
|
-
|
|
313
|
+
const name = runtime.renamedActions.get(held.name) ?? held.name;
|
|
314
|
+
const rewrite = runtime.rewrittenInputs.get(held.name);
|
|
315
|
+
const input = rewrite === undefined ? held.input : rewrite(held.input);
|
|
316
|
+
const sender = keptSender(runtime, name, input, held.operation, true);
|
|
221
317
|
try {
|
|
222
|
-
if (unsettled(await
|
|
318
|
+
if (unsettled(await sender.send()))
|
|
223
319
|
return 'again';
|
|
224
|
-
await local.dropCall(held.operation);
|
|
225
320
|
}
|
|
226
321
|
finally {
|
|
227
|
-
|
|
322
|
+
sender.release();
|
|
228
323
|
}
|
|
229
324
|
}
|
|
230
325
|
return 'done';
|
|
@@ -234,7 +329,7 @@ async function resendPass({ socket, conversations }, signal) {
|
|
|
234
329
|
return 'done';
|
|
235
330
|
const reading = { complete: true, reachable: true };
|
|
236
331
|
try {
|
|
237
|
-
await conversations
|
|
332
|
+
await resendConversations(conversations, reading);
|
|
238
333
|
}
|
|
239
334
|
catch {
|
|
240
335
|
reading.reachable = false;
|