@agentshouse/mdruntime 0.1.0-cf04ede9fb796 → 0.1.0-cf08df9b663d8
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 +175 -85
- package/dist/adapter.d.ts +226 -74
- 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 -19
- 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 +42 -27
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +29 -15
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +26 -14
- package/dist/conversation-row.d.ts +23 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +37 -8
- package/dist/conversation.d.ts +48 -16
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +368 -262
- 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 +6 -1
- 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 +1 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +6 -4
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -2
- package/dist/holdings.d.ts.map +1 -1
- package/dist/holdings.js +5 -3
- 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 +29 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -9
- package/dist/install.d.ts +10 -6
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +92 -111
- package/dist/lifecycle.d.ts +2 -2
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +80 -54
- package/dist/linked-file.d.ts +7 -0
- package/dist/linked-file.d.ts.map +1 -0
- package/dist/linked-file.js +13 -0
- package/dist/listing.d.ts +29 -22
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +71 -79
- 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 +105 -41
- package/dist/messages.d.ts +21 -6
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +53 -41
- 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 -139
- 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 +24 -10
- 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 -59
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +32 -122
- package/dist/paths.d.ts +1 -1
- package/dist/paths.js +1 -1
- 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 +1 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -8
- 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 +17 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +33 -1
- package/dist/readiness.d.ts +23 -4
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +18 -10
- package/dist/reads.d.ts +5 -3
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +30 -15
- 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 -17
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +18 -20
- 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 +15 -20
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +43 -90
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +338 -236
- package/dist/saves.d.ts +9 -45
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +208 -752
- 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 +0 -5
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +4 -90
- package/dist/shown.d.ts +10 -6
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +105 -73
- 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 +9 -7
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +19 -18
- 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 +32 -10
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +71 -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 +25 -15
- 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 +220 -62
- package/dist/surface.d.ts +20 -8
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +70 -35
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +134 -109
- package/dist/tables.d.ts +40 -57
- 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 -44
- 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;AAyDD,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,16 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { resendConversations } from './conversation.js';
|
|
1
|
+
import { classifyHref, parseRoomPath } from '@agentshouse/mdmodel';
|
|
2
|
+
import { CATCHING_UP, holdsSubmission, resendConversations } from './conversation.js';
|
|
3
3
|
import { listingNow } from './listing.js';
|
|
4
4
|
import { locked, lockedRooms } from './locks.js';
|
|
5
5
|
import { scoped } from './models.js';
|
|
6
|
-
import { ABSENT_TARGET,
|
|
6
|
+
import { ABSENT_TARGET, failure, historyAnswer, LOCKED_UNREADABLE, lockedRoom, handedOutcome, UNANSWERED, undeclared, UNCERTAIN, UNREADABLE, } from './outcome.js';
|
|
7
7
|
import { refuse } from './refusal.js';
|
|
8
|
+
import { selectorValues } from './selector.js';
|
|
8
9
|
function operationOf(input) {
|
|
9
10
|
const operation = input?.operation_id;
|
|
10
11
|
return typeof operation === 'string' ? operation : null;
|
|
11
12
|
}
|
|
12
13
|
export async function readHistory(runtime, locator, path, query = {}) {
|
|
13
|
-
const { store, socket,
|
|
14
|
+
const { store, socket, presence } = runtime;
|
|
14
15
|
const { session } = socket;
|
|
15
16
|
if (socket.closed() || session.now().refusal !== null)
|
|
16
17
|
return UNCERTAIN;
|
|
@@ -26,13 +27,7 @@ export async function readHistory(runtime, locator, path, query = {}) {
|
|
|
26
27
|
const { closed, authorization, refusal } = session.now();
|
|
27
28
|
if (closed || authorization === undefined || refusal !== null)
|
|
28
29
|
return UNCERTAIN;
|
|
29
|
-
const since =
|
|
30
|
-
const transfer = ['transfer', 'history', locator, path];
|
|
31
|
-
if (query.revision !== undefined)
|
|
32
|
-
transfer.push(query.revision);
|
|
33
|
-
if (query.pageToken !== undefined)
|
|
34
|
-
transfer.push(query.pageToken);
|
|
35
|
-
journal.record(transfer.join(' '));
|
|
30
|
+
const since = presence.losses();
|
|
36
31
|
try {
|
|
37
32
|
const result = await socket.history(authorization, {
|
|
38
33
|
locator,
|
|
@@ -40,38 +35,36 @@ export async function readHistory(runtime, locator, path, query = {}) {
|
|
|
40
35
|
...(query.revision === undefined ? {} : { revision: query.revision }),
|
|
41
36
|
...(query.pageToken === undefined ? {} : { pageToken: query.pageToken }),
|
|
42
37
|
});
|
|
43
|
-
|
|
44
|
-
if (store.fences.since(locator, since))
|
|
38
|
+
if (presence.lostSince(locator, since))
|
|
45
39
|
return failure({ kind: 'room-not-readable', locator });
|
|
46
40
|
if (result.kind === 'scoped-refusal') {
|
|
47
41
|
const room = await store.record(result.locator);
|
|
48
42
|
if (room !== undefined)
|
|
49
|
-
await scoped(runtime, result, room,
|
|
43
|
+
await scoped(runtime, result, room.locator, room.declaration);
|
|
50
44
|
}
|
|
51
45
|
if (result.kind === 'revoked-authorization')
|
|
52
46
|
await refuse(runtime, 'revoked-authorization');
|
|
53
47
|
return historyAnswer(result);
|
|
54
48
|
}
|
|
55
49
|
catch {
|
|
56
|
-
journal.record('outcome history transport-uncertainty');
|
|
57
50
|
return UNCERTAIN;
|
|
58
51
|
}
|
|
59
52
|
}
|
|
60
53
|
export async function located(runtime, room, path, destination) {
|
|
61
|
-
const crossing = roomTarget(destination);
|
|
62
54
|
const listing = await listingNow(runtime);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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 };
|
|
69
62
|
}
|
|
70
63
|
export async function resolveReference(runtime, room, path, destination) {
|
|
71
64
|
const { store } = runtime;
|
|
72
|
-
|
|
65
|
+
const kind = classifyHref(path, destination).kind;
|
|
66
|
+
if (kind !== 'path' && kind !== 'room')
|
|
73
67
|
return ABSENT_TARGET;
|
|
74
|
-
}
|
|
75
68
|
const at = await located(runtime, room, path, destination);
|
|
76
69
|
if (at === null)
|
|
77
70
|
return UNREADABLE;
|
|
@@ -94,8 +87,16 @@ export async function resolveReference(runtime, room, path, destination) {
|
|
|
94
87
|
? { kind: 'deleted', ...at, revision: last }
|
|
95
88
|
: { kind: 'document', ...at };
|
|
96
89
|
}
|
|
97
|
-
async function
|
|
98
|
-
|
|
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)) {
|
|
99
100
|
for (const action of capability.actions ?? []) {
|
|
100
101
|
if (action.name === name)
|
|
101
102
|
return action;
|
|
@@ -103,69 +104,91 @@ async function declaredAction({ store }, name) {
|
|
|
103
104
|
}
|
|
104
105
|
return undefined;
|
|
105
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 FOLDER_END = /\/$/u;
|
|
119
|
+
function namedRoom(path) {
|
|
120
|
+
return parseRoomPath(path.replace(FOLDER_END, ''))?.handle ?? null;
|
|
121
|
+
}
|
|
106
122
|
async function calledRooms(runtime, name, input) {
|
|
107
|
-
const
|
|
108
|
-
if (
|
|
123
|
+
const declared = await declaration(runtime, name);
|
|
124
|
+
if (declared === undefined || input === null || typeof input !== 'object')
|
|
109
125
|
return [];
|
|
110
|
-
const named =
|
|
111
|
-
|
|
126
|
+
const named = declared.room === undefined ? [] : strings(selectorValues(input, declared.room));
|
|
127
|
+
const handles = strings((declared.roomPaths ?? []).flatMap((selector) => selectorValues(input, selector))).flatMap((path) => namedRoom(path) ?? []);
|
|
128
|
+
if (handles.length === 0)
|
|
129
|
+
return named;
|
|
130
|
+
const listing = await listingNow(runtime);
|
|
131
|
+
return [
|
|
132
|
+
...named,
|
|
133
|
+
...[...listing.values()]
|
|
134
|
+
.filter((listed) => handles.includes(listed.handle) || handles.includes(listed.locator))
|
|
135
|
+
.map((listed) => listed.locator),
|
|
136
|
+
];
|
|
112
137
|
}
|
|
113
|
-
export async function invokeAction(runtime, name, input, dispatching) {
|
|
114
|
-
const { store, socket,
|
|
138
|
+
export async function invokeAction(runtime, name, input, { dispatching, attempt } = {}) {
|
|
139
|
+
const { store, socket, retries } = runtime;
|
|
115
140
|
const { session } = socket;
|
|
116
141
|
await socket.ready;
|
|
117
|
-
if (socket.closed() || session.now().refusal !== null)
|
|
118
|
-
return
|
|
119
|
-
|
|
120
|
-
|
|
142
|
+
if (socket.closed() || session.now().refusal !== null) {
|
|
143
|
+
return handedOutcome(retries, attempt, UNANSWERED);
|
|
144
|
+
}
|
|
145
|
+
if ((await declaredAction(runtime, name)) === undefined) {
|
|
146
|
+
return session.now().roomsNamed
|
|
147
|
+
? undeclared(name)
|
|
148
|
+
: handedOutcome(retries, attempt, UNANSWERED);
|
|
149
|
+
}
|
|
121
150
|
try {
|
|
122
151
|
await socket.authorize();
|
|
123
152
|
}
|
|
124
153
|
catch {
|
|
125
|
-
return
|
|
154
|
+
return handedOutcome(retries, attempt, UNANSWERED);
|
|
126
155
|
}
|
|
127
156
|
const { closed, authorization, refusal } = session.now();
|
|
128
|
-
if (closed || authorization === undefined || refusal !== null)
|
|
129
|
-
return
|
|
157
|
+
if (closed || authorization === undefined || refusal !== null) {
|
|
158
|
+
return handedOutcome(retries, attempt, UNANSWERED);
|
|
159
|
+
}
|
|
130
160
|
await dispatching?.();
|
|
131
|
-
journal.record(`transfer action ${name}`);
|
|
132
161
|
try {
|
|
133
162
|
const result = await socket.action(authorization, { name, input });
|
|
134
163
|
if (result.kind === 'scoped-refusal') {
|
|
135
164
|
const room = await store.record(result.locator);
|
|
136
165
|
if (room !== undefined)
|
|
137
|
-
await scoped(runtime, result, room,
|
|
166
|
+
await scoped(runtime, result, room.locator, room.declaration);
|
|
138
167
|
}
|
|
139
168
|
if (result.kind === 'revoked-authorization')
|
|
140
169
|
await refuse(runtime, 'revoked-authorization');
|
|
141
|
-
|
|
142
|
-
if (result.kind === 'rejected')
|
|
143
|
-
journal.record(`refusal rejected ${result.code}`);
|
|
144
|
-
return calledResult(result);
|
|
170
|
+
return handedOutcome(retries, attempt, result);
|
|
145
171
|
}
|
|
146
|
-
catch {
|
|
147
|
-
|
|
148
|
-
return UNCERTAIN;
|
|
172
|
+
catch (error) {
|
|
173
|
+
return handedOutcome(retries, attempt, { kind: 'transport-uncertainty', failure: error });
|
|
149
174
|
}
|
|
150
175
|
}
|
|
151
176
|
export async function readConversationHistory(runtime, request) {
|
|
152
|
-
const { socket,
|
|
177
|
+
const { socket, retries } = runtime;
|
|
178
|
+
const caught = { step: 'conversations', instance: CATCHING_UP };
|
|
153
179
|
await socket.ready;
|
|
154
180
|
const stream = socket.conversations();
|
|
155
181
|
if (socket.closed() || socket.session.now().refusal !== null || stream?.history === undefined) {
|
|
156
|
-
return
|
|
182
|
+
return handedOutcome(retries, caught, UNANSWERED);
|
|
157
183
|
}
|
|
158
|
-
journal.record('transfer conversation history');
|
|
159
184
|
try {
|
|
160
185
|
const result = await stream.history(request);
|
|
161
186
|
if (result.kind === 'revoked-authorization')
|
|
162
187
|
await refuse(runtime, 'revoked-authorization');
|
|
163
|
-
|
|
164
|
-
return calledResult(result);
|
|
188
|
+
return handedOutcome(retries, caught, result);
|
|
165
189
|
}
|
|
166
|
-
catch {
|
|
167
|
-
|
|
168
|
-
return UNCERTAIN;
|
|
190
|
+
catch (error) {
|
|
191
|
+
return handedOutcome(retries, caught, { kind: 'transport-uncertainty', failure: error });
|
|
169
192
|
}
|
|
170
193
|
}
|
|
171
194
|
function unsettled(result) {
|
|
@@ -173,59 +196,126 @@ function unsettled(result) {
|
|
|
173
196
|
return false;
|
|
174
197
|
return result.retryable && (result.kind !== 'rejected' || result.reset === undefined);
|
|
175
198
|
}
|
|
176
|
-
|
|
177
|
-
|
|
199
|
+
function numberedCall(runtime, name, input, operation, dispatching) {
|
|
200
|
+
return invokeAction(runtime, name, input, {
|
|
201
|
+
dispatching,
|
|
202
|
+
attempt: { step: 'sending', instance: `action ${operation}` },
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function keptSender(runtime, name, input, operation, resent = false) {
|
|
206
|
+
const { store, socket } = runtime;
|
|
178
207
|
const { lanes } = socket;
|
|
208
|
+
const dispatching = async () => (await store.open()).keepCall({ operation, name, input });
|
|
209
|
+
let waiting = [];
|
|
210
|
+
let last = UNCERTAIN;
|
|
211
|
+
let lost = resent;
|
|
212
|
+
const tell = (result) => {
|
|
213
|
+
last = result;
|
|
214
|
+
const told = waiting;
|
|
215
|
+
waiting = [];
|
|
216
|
+
for (const answer of told)
|
|
217
|
+
answer(result);
|
|
218
|
+
};
|
|
219
|
+
const sender = {
|
|
220
|
+
next: () => new Promise((answer) => waiting.push(answer)),
|
|
221
|
+
async send() {
|
|
222
|
+
let result;
|
|
223
|
+
try {
|
|
224
|
+
result = await numberedCall(runtime, name, input, operation, dispatching);
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
tell(last);
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
if (unsettled(result))
|
|
231
|
+
lost = true;
|
|
232
|
+
else {
|
|
233
|
+
await (await store.open()).dropCall(operation);
|
|
234
|
+
lanes.settle(operation, lost);
|
|
235
|
+
}
|
|
236
|
+
tell(result);
|
|
237
|
+
return result;
|
|
238
|
+
},
|
|
239
|
+
release() {
|
|
240
|
+
lanes.sent(operation, sender);
|
|
241
|
+
tell(last);
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
lanes.sending(operation, sender);
|
|
245
|
+
return sender;
|
|
246
|
+
}
|
|
247
|
+
async function recoveredAction(runtime, name, input, attempt) {
|
|
248
|
+
const { socket, recovery } = runtime;
|
|
179
249
|
const operation = operationOf(input);
|
|
180
250
|
if (operation === null)
|
|
181
|
-
return invokeAction(runtime, name, input);
|
|
182
|
-
const
|
|
183
|
-
|
|
251
|
+
return invokeAction(runtime, name, input, { attempt });
|
|
252
|
+
const held = socket.lanes.sender(operation);
|
|
253
|
+
if (held !== undefined)
|
|
254
|
+
return held.next();
|
|
255
|
+
const sender = keptSender(runtime, name, input, operation);
|
|
256
|
+
let first;
|
|
184
257
|
try {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (!socket.isOpen())
|
|
191
|
-
return 'again';
|
|
192
|
-
result = await invokeAction(runtime, name, input, kept);
|
|
193
|
-
return unsettled(result) ? 'again' : 'done';
|
|
194
|
-
}, { again: true });
|
|
195
|
-
}
|
|
196
|
-
if (!unsettled(result))
|
|
197
|
-
await (await store.open()).dropCall(operation);
|
|
198
|
-
return result;
|
|
258
|
+
first = await sender.send();
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
sender.release();
|
|
262
|
+
throw error;
|
|
199
263
|
}
|
|
200
|
-
|
|
201
|
-
|
|
264
|
+
if (!unsettled(first)) {
|
|
265
|
+
sender.release();
|
|
266
|
+
return first;
|
|
202
267
|
}
|
|
268
|
+
void recovery
|
|
269
|
+
.attempt(`action ${operation}`, async () => {
|
|
270
|
+
if (socket.closed() || socket.session.now().refusal !== null)
|
|
271
|
+
return 'done';
|
|
272
|
+
if (!socket.isOpen())
|
|
273
|
+
return 'again';
|
|
274
|
+
return unsettled(await sender.send()) ? 'again' : 'done';
|
|
275
|
+
}, { again: true })
|
|
276
|
+
.finally(() => sender.release());
|
|
277
|
+
return first;
|
|
203
278
|
}
|
|
204
|
-
export async function called(runtime, name, input) {
|
|
279
|
+
export async function called(runtime, name, input, attempt) {
|
|
205
280
|
await runtime.socket.ready;
|
|
206
281
|
const lockedNow = await lockedRooms(runtime);
|
|
207
282
|
const room = (await calledRooms(runtime, name, input)).find((one) => lockedNow.includes(one));
|
|
208
|
-
return room === undefined ? recoveredAction(runtime, name, input) : lockedRoom(room);
|
|
283
|
+
return room === undefined ? recoveredAction(runtime, name, input, attempt) : lockedRoom(room);
|
|
209
284
|
}
|
|
210
|
-
export async function
|
|
285
|
+
export async function answeredCall(runtime, operation) {
|
|
211
286
|
const { store, socket } = runtime;
|
|
212
287
|
const { lanes } = socket;
|
|
288
|
+
const held = () => lanes.sender(operation) !== undefined || lanes.unclaimed(operation);
|
|
289
|
+
if (!held()) {
|
|
290
|
+
const calls = await (await store.open()).calls();
|
|
291
|
+
const kept = calls.some((one) => one.operation === operation) ||
|
|
292
|
+
(await holdsSubmission(runtime.conversations, operation));
|
|
293
|
+
if (!held() && !kept)
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
await lanes.settled(operation);
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
export async function resendCalls(runtime, signal) {
|
|
300
|
+
const { store, socket } = runtime;
|
|
213
301
|
if (!socket.isOpen() || socket.closed() || socket.stopping())
|
|
214
302
|
return 'done';
|
|
215
303
|
const local = await store.open();
|
|
216
304
|
for (const held of await local.calls()) {
|
|
217
|
-
if (lanes.
|
|
305
|
+
if (socket.lanes.sender(held.operation) !== undefined)
|
|
218
306
|
continue;
|
|
219
307
|
if (socket.closed() || signal.aborted)
|
|
220
308
|
return 'done';
|
|
221
|
-
|
|
309
|
+
const name = runtime.renamedActions.get(held.name) ?? held.name;
|
|
310
|
+
const rewrite = runtime.rewrittenInputs.get(held.name);
|
|
311
|
+
const input = runtime.keptInput(rewrite === undefined ? held.input : rewrite(held.input));
|
|
312
|
+
const sender = keptSender(runtime, name, input, held.operation, true);
|
|
222
313
|
try {
|
|
223
|
-
if (unsettled(await
|
|
314
|
+
if (unsettled(await sender.send()))
|
|
224
315
|
return 'again';
|
|
225
|
-
await local.dropCall(held.operation);
|
|
226
316
|
}
|
|
227
317
|
finally {
|
|
228
|
-
|
|
318
|
+
sender.release();
|
|
229
319
|
}
|
|
230
320
|
}
|
|
231
321
|
return 'done';
|