@agentshouse/mdruntime 0.1.0-c806ecaf4afed → 0.1.0-c809974611fbc
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.map +1 -1
- package/dist/acceptance.js +45 -25
- package/dist/act-lanes.d.ts +11 -14
- package/dist/act-lanes.d.ts.map +1 -1
- package/dist/act-lanes.js +53 -5
- package/dist/actions.d.ts +8 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +161 -71
- package/dist/adapter.d.ts +165 -29
- 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 +347 -0
- package/dist/chain.d.ts +1 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +5 -2
- package/dist/change.d.ts +6 -2
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +3 -0
- 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 +27 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +29 -57
- package/dist/collection.d.ts +6 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +23 -9
- 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 +88 -44
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +23 -16
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +23 -10
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +18 -8
- package/dist/conversation-row.d.ts +8 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +20 -7
- package/dist/conversation.d.ts +31 -12
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +264 -190
- package/dist/declaration.js +3 -3
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +36 -9
- 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 +25 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +111 -34
- package/dist/expectation.d.ts +25 -14
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +51 -20
- package/dist/failure.d.ts +2 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +6 -1
- 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/host.d.ts +7 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +78 -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 +24 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -7
- package/dist/install.d.ts +10 -4
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +45 -46
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +52 -32
- package/dist/listing.d.ts +24 -12
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +50 -21
- package/dist/live.d.ts +19 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +94 -36
- 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.map +1 -1
- package/dist/locks.js +4 -3
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +2 -3
- package/dist/media.d.ts +19 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +181 -34
- package/dist/memory.d.ts +7 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +66 -22
- package/dist/messages.d.ts +17 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +29 -10
- 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 -7
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +5 -8
- 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 +206 -69
- 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 +5 -5
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +2 -2
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +22 -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 +21 -7
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +112 -39
- package/dist/parts.d.ts +4 -9
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +30 -15
- 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 +198 -87
- package/dist/presence.d.ts +8 -2
- package/dist/presence.d.ts.map +1 -1
- package/dist/presence.js +24 -13
- package/dist/queries.d.ts +2 -2
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +133 -73
- package/dist/query.d.ts +2 -2
- 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 +2 -2
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +73 -48
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +180 -39
- package/dist/react.d.ts +16 -11
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +22 -4
- 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 +4 -2
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +22 -7
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +31 -8
- package/dist/reference-forms.d.ts +4 -0
- package/dist/reference-forms.d.ts.map +1 -0
- package/dist/reference-forms.js +74 -0
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +4 -4
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +1 -3
- package/dist/replica.d.ts +3 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +5 -5
- 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 +31 -6
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +262 -36
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +12 -7
- 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 -2
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +24 -10
- package/dist/run-tables.d.ts +25 -0
- package/dist/run-tables.d.ts.map +1 -0
- package/dist/run-tables.js +94 -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 +90 -0
- package/dist/runtime.d.ts +7 -4
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +2 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +105 -124
- package/dist/saves.d.ts +7 -5
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +107 -57
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +2 -2
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- package/dist/shown.d.ts +5 -2
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +79 -43
- 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 -1
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket/session.js +3 -0
- package/dist/socket.d.ts +7 -4
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +11 -9
- package/dist/source.d.ts +7 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +15 -2
- 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 +30 -8
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +70 -26
- 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.d.ts +17 -10
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +18 -6
- package/dist/stored.d.ts +41 -16
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +215 -57
- package/dist/surface.d.ts +20 -8
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +62 -27
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +76 -40
- package/dist/tables.d.ts +41 -52
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +110 -326
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +3 -4
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +50 -10
- package/dist/wire.d.ts +40 -16
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +22 -14
- package/package.json +4 -4
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
- package/dist/log.d.ts +0 -6
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
package/dist/actions.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { roomTarget, target } from '@agentshouse/mdmodel';
|
|
2
|
-
import { resendConversations } from './conversation.js';
|
|
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, presence
|
|
14
|
+
const { store, socket, presence } = runtime;
|
|
14
15
|
const { session } = socket;
|
|
15
16
|
if (socket.closed() || session.now().refusal !== null)
|
|
16
17
|
return UNCERTAIN;
|
|
@@ -27,12 +28,6 @@ export async function readHistory(runtime, locator, path, query = {}) {
|
|
|
27
28
|
if (closed || authorization === undefined || refusal !== null)
|
|
28
29
|
return UNCERTAIN;
|
|
29
30
|
const since = presence.losses();
|
|
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(' '));
|
|
36
31
|
try {
|
|
37
32
|
const result = await socket.history(authorization, {
|
|
38
33
|
locator,
|
|
@@ -40,7 +35,6 @@ 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
|
-
journal.record(`outcome history ${result.kind}`);
|
|
44
38
|
if (presence.lostSince(locator, since))
|
|
45
39
|
return failure({ kind: 'room-not-readable', locator });
|
|
46
40
|
if (result.kind === 'scoped-refusal') {
|
|
@@ -53,7 +47,6 @@ export async function readHistory(runtime, locator, path, query = {}) {
|
|
|
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
|
}
|
|
@@ -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,32 +104,60 @@ 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 ROOM_TOP = /^\/rooms\/([^/]+)\/?$/u;
|
|
119
|
+
function namedRoom(path) {
|
|
120
|
+
return roomTarget(path)?.handle ?? ROOM_TOP.exec(path)?.[1] ?? 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') {
|
|
@@ -138,34 +167,28 @@ export async function invokeAction(runtime, name, input, dispatching) {
|
|
|
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
|
-
if (unsettled(result)) {
|
|
187
|
-
await recovery.attempt(`action ${operation}`, async () => {
|
|
188
|
-
if (socket.closed() || socket.session.now().refusal !== null)
|
|
189
|
-
return 'done';
|
|
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();
|
|
199
259
|
}
|
|
200
|
-
|
|
201
|
-
|
|
260
|
+
catch (error) {
|
|
261
|
+
sender.release();
|
|
262
|
+
throw error;
|
|
202
263
|
}
|
|
264
|
+
if (!unsettled(first)) {
|
|
265
|
+
sender.release();
|
|
266
|
+
return first;
|
|
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) ?? runtime.rewrittenInputs.get(name);
|
|
311
|
+
const input = 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';
|