@agentshouse/mdruntime 0.1.0-c850521dcad03 → 0.1.0-c8aadbf0beec5
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 +75 -165
- 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 +143 -72
- package/dist/adapter.d.ts +113 -57
- 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 +0 -5
- 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/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 +4 -0
- 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 +0 -2
- package/dist/client.d.ts +19 -21
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +45 -58
- package/dist/collection.d.ts +26 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +28 -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 +2 -0
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +31 -25
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +39 -27
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +152 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +261 -0
- 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 +55 -45
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +976 -1033
- 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 +6 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +24 -12
- 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 -0
- 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 +23 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +83 -19
- package/dist/house-query.d.ts +21 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +41 -0
- package/dist/index.d.ts +21 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -6
- 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 +79 -56
- 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 +5 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +74 -33
- package/dist/loaded.d.ts +5 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +40 -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 +19 -2
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +105 -27
- package/dist/memory.d.ts +9 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +94 -32
- package/dist/messages.d.ts +12 -6
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +34 -38
- 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 +4 -3
- 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/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 +1 -1
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +5 -5
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +24 -11
- package/dist/outcome.d.ts +13 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +32 -2
- package/dist/overlay.d.ts +6 -2
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +37 -24
- 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 +5 -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 +32 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +201 -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 +86 -71
- package/dist/query.d.ts +0 -1
- 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 +1 -7
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +480 -0
- package/dist/reach.d.ts +14 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +164 -33
- package/dist/react.d.ts +15 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +33 -1
- package/dist/readiness.d.ts +16 -5
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +10 -10
- package/dist/reads.d.ts +5 -2
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +49 -7
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +31 -8
- package/dist/refresh.js +2 -2
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +5 -6
- package/dist/replica.d.ts +5 -10
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +17 -18
- 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 -8
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +273 -66
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +22 -18
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +45 -0
- package/dist/rows.d.ts +2 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +9 -10
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runtime.d.ts +13 -20
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +42 -86
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +326 -225
- package/dist/saves.d.ts +4 -40
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +143 -710
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +4 -5
- 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 +9 -5
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +99 -67
- 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 +4 -6
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +6 -16
- package/dist/source.d.ts +5 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +18 -6
- 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 +23 -8
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +84 -24
- 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 +26 -14
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +101 -36
- package/dist/surface.d.ts +13 -7
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +70 -37
- package/dist/sync.d.ts +4 -3
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +135 -109
- package/dist/tables.d.ts +19 -58
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +91 -332
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +6 -7
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +4 -10
- package/dist/wire.d.ts +66 -7
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +25 -9
- package/package.json +3 -2
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- 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
package/dist/reads.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { refusedForSpace } from './durability.js';
|
|
2
|
+
import { uncaught } from './failure.js';
|
|
2
3
|
import { answeredResult, UNCERTAIN } from './outcome.js';
|
|
3
4
|
export const READ_TABLES = [
|
|
4
5
|
'CREATE TABLE read_answers (name TEXT NOT NULL, input TEXT NOT NULL, build TEXT NOT NULL, answer TEXT NOT NULL, PRIMARY KEY (name, input)) WITHOUT ROWID',
|
|
@@ -37,6 +38,8 @@ export function readAnswers(options) {
|
|
|
37
38
|
await database.ask({ kind: 'read.keep', ...read.at, answer }).catch((error) => {
|
|
38
39
|
if (refusedForSpace(error))
|
|
39
40
|
options.filled();
|
|
41
|
+
else
|
|
42
|
+
uncaught(error);
|
|
40
43
|
});
|
|
41
44
|
}
|
|
42
45
|
async function asked(read, led) {
|
|
@@ -44,7 +47,11 @@ export function readAnswers(options) {
|
|
|
44
47
|
read.owed = true;
|
|
45
48
|
return;
|
|
46
49
|
}
|
|
47
|
-
const
|
|
50
|
+
const attempt = { step: 'reading', instance: read.key };
|
|
51
|
+
const result = await options.call(read.at.name, read.asked, attempt).catch((error) => {
|
|
52
|
+
options.retries.failed(attempt.step, attempt.instance, error);
|
|
53
|
+
return UNCERTAIN;
|
|
54
|
+
});
|
|
48
55
|
if (options.closed())
|
|
49
56
|
return;
|
|
50
57
|
read.owed = !answered(result);
|
|
@@ -62,14 +69,43 @@ export function readAnswers(options) {
|
|
|
62
69
|
if (!options.closed())
|
|
63
70
|
show(read, { ...read.shown, answer, failure: null });
|
|
64
71
|
}
|
|
72
|
+
function lost(read) {
|
|
73
|
+
return read.owed && read.shown.failure?.kind === 'transport-uncertainty' && options.streaming();
|
|
74
|
+
}
|
|
75
|
+
function retrying(read) {
|
|
76
|
+
return `${read.key} again`;
|
|
77
|
+
}
|
|
78
|
+
function askedLater(read) {
|
|
79
|
+
void recovery.attempt(retrying(read), async () => {
|
|
80
|
+
if (options.closed() || read.observers.size === 0 || !lost(read))
|
|
81
|
+
return 'done';
|
|
82
|
+
await attempted(read);
|
|
83
|
+
return lost(read) ? 'again' : 'done';
|
|
84
|
+
}, { again: true });
|
|
85
|
+
}
|
|
65
86
|
function forgotten(read) {
|
|
66
87
|
read.text = null;
|
|
67
88
|
read.shown = { ...read.shown, answer: null, failure: null };
|
|
68
89
|
}
|
|
69
|
-
function
|
|
70
|
-
|
|
90
|
+
function attempted(read, led) {
|
|
91
|
+
read.asking = true;
|
|
92
|
+
return recovery
|
|
93
|
+
.attempt(read.key, async () => {
|
|
71
94
|
await asked(read, led);
|
|
72
95
|
return 'done';
|
|
96
|
+
})
|
|
97
|
+
.finally(() => {
|
|
98
|
+
const unanswered = read.joined && read.owed;
|
|
99
|
+
read.asking = false;
|
|
100
|
+
read.joined = false;
|
|
101
|
+
if (unanswered)
|
|
102
|
+
void ask(read);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function ask(read, led) {
|
|
106
|
+
return attempted(read, led).finally(() => {
|
|
107
|
+
if (lost(read))
|
|
108
|
+
askedLater(read);
|
|
73
109
|
});
|
|
74
110
|
}
|
|
75
111
|
function opened(name, input, key) {
|
|
@@ -83,6 +119,8 @@ export function readAnswers(options) {
|
|
|
83
119
|
text: null,
|
|
84
120
|
shown: { answer: null, failure: null, kept: held },
|
|
85
121
|
owed: false,
|
|
122
|
+
asking: false,
|
|
123
|
+
joined: false,
|
|
86
124
|
};
|
|
87
125
|
if (held) {
|
|
88
126
|
read.stored = database.ask({ kind: 'read.stored', ...read.at }).then((text) => {
|
|
@@ -90,7 +128,7 @@ export function readAnswers(options) {
|
|
|
90
128
|
return;
|
|
91
129
|
read.text = text;
|
|
92
130
|
read.shown = { ...read.shown, answer: JSON.parse(text) };
|
|
93
|
-
},
|
|
131
|
+
}, uncaught);
|
|
94
132
|
}
|
|
95
133
|
reads.set(key, read);
|
|
96
134
|
return read;
|
|
@@ -106,7 +144,10 @@ export function readAnswers(options) {
|
|
|
106
144
|
if (!read.shown.kept)
|
|
107
145
|
forgotten(read);
|
|
108
146
|
deliver(read.shown);
|
|
109
|
-
|
|
147
|
+
if (read.asking)
|
|
148
|
+
read.joined = true;
|
|
149
|
+
else
|
|
150
|
+
void ask(read);
|
|
110
151
|
});
|
|
111
152
|
return () => {
|
|
112
153
|
read.observers.delete(deliver);
|
|
@@ -114,15 +155,16 @@ export function readAnswers(options) {
|
|
|
114
155
|
reads.delete(key);
|
|
115
156
|
};
|
|
116
157
|
},
|
|
117
|
-
again() {
|
|
158
|
+
again(first = Promise.resolve()) {
|
|
118
159
|
const all = [...reads.values()];
|
|
119
|
-
const led = Promise.all(all.filter(leads).map((read) => ask(read)));
|
|
160
|
+
const led = Promise.all([first, ...all.filter(leads).map((read) => ask(read, first))]);
|
|
120
161
|
for (const read of all)
|
|
121
162
|
if (!leads(read))
|
|
122
163
|
void ask(read, led);
|
|
123
164
|
},
|
|
124
165
|
reopened() {
|
|
125
166
|
for (const read of reads.values()) {
|
|
167
|
+
recovery.cancel(retrying(read));
|
|
126
168
|
if (read.text === null) {
|
|
127
169
|
if (read.owed)
|
|
128
170
|
void ask(read);
|
package/dist/recovery.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export type Attempt = (signal: AbortSignal) => Promise<Attempted>;
|
|
|
5
5
|
export type AttemptOptions = {
|
|
6
6
|
readonly at?: number;
|
|
7
7
|
readonly again?: boolean;
|
|
8
|
+
readonly attempts?: number;
|
|
8
9
|
};
|
|
9
10
|
export type RecoveryOptions = {
|
|
10
11
|
readonly firstMs?: number;
|
|
@@ -16,11 +17,13 @@ export type Recovery = {
|
|
|
16
17
|
attempt(intent: string, run: Attempt, options?: AttemptOptions): Promise<boolean>;
|
|
17
18
|
pending(intent: string): boolean;
|
|
18
19
|
resume(): void;
|
|
20
|
+
again(): void;
|
|
21
|
+
waits(wake: () => void): () => void;
|
|
19
22
|
cancel(intent: string): void;
|
|
20
23
|
scope(inFlight?: number): Recovery;
|
|
21
24
|
retire(): Promise<void>;
|
|
22
25
|
};
|
|
23
26
|
export declare function retryDelay(tries: number, firstMs?: number, maxMs?: number): number;
|
|
24
|
-
export declare function untilAnswered<T>(ask: () => Promise<T>, signal: AbortSignal, answered?: (answer: T) => boolean): Promise<T>;
|
|
27
|
+
export declare function untilAnswered<T>(ask: () => Promise<T>, signal: AbortSignal, answered?: (answer: T) => boolean, owner?: Recovery): Promise<T>;
|
|
25
28
|
export declare function createRecovery(options?: RecoveryOptions): Recovery;
|
|
26
29
|
//# sourceMappingURL=recovery.d.ts.map
|
package/dist/recovery.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../src/recovery.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG;IAA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C,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IACnC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB,CAAC;AAuBF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,SAAW,EAAE,KAAK,SAAS,GAAG,MAAM,CAGpF;AAED,wBAAsB,aAAa,CAAC,CAAC,EACnC,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACrB,MAAM,EAAE,WAAW,EACnB,QAAQ,GAAE,CAAC,MAAM,EAAE,CAAC,KAAK,OAAoB,EAC7C,KAAK,CAAC,EAAE,QAAQ,GACf,OAAO,CAAC,CAAC,CAAC,CAsBZ;AAiMD,wBAAgB,cAAc,CAAC,OAAO,GAAE,eAAoB,GAAG,QAAQ,CAStE"}
|
package/dist/recovery.js
CHANGED
|
@@ -7,7 +7,7 @@ export function retryDelay(tries, firstMs = FIRST_MS, maxMs = MAX_MS) {
|
|
|
7
7
|
const longest = Math.min(maxMs, firstMs * 2 ** tries);
|
|
8
8
|
return longest / 2 + (Math.random() * longest) / 2;
|
|
9
9
|
}
|
|
10
|
-
export async function untilAnswered(ask, signal, answered = () => true) {
|
|
10
|
+
export async function untilAnswered(ask, signal, answered = () => true, owner) {
|
|
11
11
|
for (let tries = 0;; tries += 1) {
|
|
12
12
|
try {
|
|
13
13
|
const answer = await ask();
|
|
@@ -19,16 +19,16 @@ export async function untilAnswered(ask, signal, answered = () => true) {
|
|
|
19
19
|
throw error;
|
|
20
20
|
}
|
|
21
21
|
await new Promise((resume) => {
|
|
22
|
-
const
|
|
22
|
+
const done = () => {
|
|
23
23
|
clearTimeout(again);
|
|
24
|
+
signal.removeEventListener('abort', done);
|
|
25
|
+
unheld();
|
|
24
26
|
resume();
|
|
25
27
|
};
|
|
26
28
|
// A read that failed is asked again on the doubling backoff, so its asker is answered once the failure clears.
|
|
27
|
-
const again = setTimeout(()
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}, retryDelay(tries));
|
|
31
|
-
signal.addEventListener('abort', stop, { once: true });
|
|
29
|
+
const again = setTimeout(done, retryDelay(tries));
|
|
30
|
+
signal.addEventListener('abort', done, { once: true });
|
|
31
|
+
const unheld = owner?.waits(done) ?? (() => { });
|
|
32
32
|
});
|
|
33
33
|
signal.throwIfAborted();
|
|
34
34
|
}
|
|
@@ -38,6 +38,7 @@ function owner(backoff, inFlight, release = () => { }) {
|
|
|
38
38
|
const children = new Set();
|
|
39
39
|
const running = new Set();
|
|
40
40
|
const queued = [];
|
|
41
|
+
const waiting = new Set();
|
|
41
42
|
let free = inFlight;
|
|
42
43
|
let retired = false;
|
|
43
44
|
function finish(key, intent, done) {
|
|
@@ -105,7 +106,7 @@ function owner(backoff, inFlight, release = () => { }) {
|
|
|
105
106
|
return;
|
|
106
107
|
}
|
|
107
108
|
intent.tries += 1;
|
|
108
|
-
if (intent.tries >=
|
|
109
|
+
if (intent.tries >= intent.attempts) {
|
|
109
110
|
if (again === null) {
|
|
110
111
|
finish(key, intent, false);
|
|
111
112
|
return;
|
|
@@ -157,6 +158,7 @@ function owner(backoff, inFlight, release = () => { }) {
|
|
|
157
158
|
const intent = {
|
|
158
159
|
run,
|
|
159
160
|
tries: 0,
|
|
161
|
+
attempts: options.attempts ?? backoff.attempts,
|
|
160
162
|
timer: null,
|
|
161
163
|
due: null,
|
|
162
164
|
guided: false,
|
|
@@ -195,6 +197,27 @@ function owner(backoff, inFlight, release = () => { }) {
|
|
|
195
197
|
launch(key, intent);
|
|
196
198
|
}
|
|
197
199
|
},
|
|
200
|
+
again() {
|
|
201
|
+
if (retired)
|
|
202
|
+
return;
|
|
203
|
+
for (const [key, intent] of [...intents]) {
|
|
204
|
+
if (intent.timer === null || intent.guided)
|
|
205
|
+
continue;
|
|
206
|
+
clearTimeout(intent.timer);
|
|
207
|
+
intent.timer = null;
|
|
208
|
+
launch(key, intent);
|
|
209
|
+
}
|
|
210
|
+
for (const wake of [...waiting])
|
|
211
|
+
wake();
|
|
212
|
+
for (const child of [...children])
|
|
213
|
+
child.again();
|
|
214
|
+
},
|
|
215
|
+
waits(wake) {
|
|
216
|
+
waiting.add(wake);
|
|
217
|
+
return () => {
|
|
218
|
+
waiting.delete(wake);
|
|
219
|
+
};
|
|
220
|
+
},
|
|
198
221
|
cancel(key) {
|
|
199
222
|
const intent = intents.get(key);
|
|
200
223
|
if (intent === undefined)
|
package/dist/refresh.js
CHANGED
|
@@ -129,7 +129,7 @@ export async function advancement(refresh, authorization, held, remodel, continu
|
|
|
129
129
|
return unconfirmed;
|
|
130
130
|
const first = await refresh(authorization, {
|
|
131
131
|
locator,
|
|
132
|
-
selection: held.replica.selection,
|
|
132
|
+
selection: held.declaration.replica.selection,
|
|
133
133
|
fromRoomVersion,
|
|
134
134
|
});
|
|
135
135
|
if (first.kind !== 'net-advancement')
|
|
@@ -154,7 +154,7 @@ export async function advancement(refresh, authorization, held, remodel, continu
|
|
|
154
154
|
return unconfirmed;
|
|
155
155
|
const page = await refresh(authorization, {
|
|
156
156
|
locator,
|
|
157
|
-
selection: held.replica.selection,
|
|
157
|
+
selection: held.declaration.replica.selection,
|
|
158
158
|
fromRoomVersion,
|
|
159
159
|
pageToken,
|
|
160
160
|
});
|
package/dist/refusal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAQpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,wBAAsB,MAAM,CAC1B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,aAAa,EACrB,QAAQ,GAAE,eAAe,GAAG,IAAW,iBAiDxC"}
|
package/dist/refusal.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { changeSet, mergeChangeSets } from './change-set.js';
|
|
2
2
|
import { composedOf } from './collection.js';
|
|
3
|
+
import { uncaught } from './failure.js';
|
|
3
4
|
import { listedLocators } from './listing.js';
|
|
4
5
|
import { prepare } from './preparation.js';
|
|
5
6
|
import { storedRecord } from './replica.js';
|
|
6
7
|
import { emitRefusal } from './shown.js';
|
|
7
8
|
export async function refuse(runtime, reason, provider = null) {
|
|
8
|
-
const { store, socket,
|
|
9
|
+
const { store, socket, presence } = runtime;
|
|
9
10
|
socket.session.set({ paused: true });
|
|
10
11
|
socket.abortReads();
|
|
11
12
|
try {
|
|
@@ -28,13 +29,13 @@ export async function refuse(runtime, reason, provider = null) {
|
|
|
28
29
|
}),
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
|
-
catch {
|
|
32
|
-
|
|
32
|
+
catch (error) {
|
|
33
|
+
uncaught(error);
|
|
33
34
|
}
|
|
34
35
|
const listedNow = listedLocators(runtime, held);
|
|
35
36
|
for (const locator of listedNow) {
|
|
36
37
|
if (!held.has(locator))
|
|
37
|
-
|
|
38
|
+
presence.modelled(locator, revoked);
|
|
38
39
|
}
|
|
39
40
|
store.changed(mergeChangeSets(listedNow.map((locator) => changeSet(locator, { documents: null, room: true }))));
|
|
40
41
|
prepare(runtime);
|
|
@@ -45,12 +46,10 @@ export async function refuse(runtime, reason, provider = null) {
|
|
|
45
46
|
socket.session.set({
|
|
46
47
|
refusal: {
|
|
47
48
|
code: reason,
|
|
48
|
-
retryable: false,
|
|
49
49
|
reauthorizationOffered: reason === 'revoked-authorization',
|
|
50
50
|
refusal: provider,
|
|
51
51
|
},
|
|
52
52
|
});
|
|
53
|
-
journal.record(`connection refused ${reason}`);
|
|
54
53
|
emitRefusal(runtime);
|
|
55
54
|
}
|
|
56
55
|
}
|
package/dist/replica.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TypedPath } from '@agentshouse/mdmodel';
|
|
2
|
-
import type { BootstrapInventory, SavedFacts, MutationResult,
|
|
2
|
+
import type { BootstrapInventory, SavedFacts, MutationResult, RoomDeclaration, TypedSelection } from './adapter.js';
|
|
3
3
|
import { type ChangeBatch, type Precondition } from './change.js';
|
|
4
4
|
import { type Collection, type Composition } from './collection.js';
|
|
5
5
|
import { type ModelState } from './model.js';
|
|
@@ -7,13 +7,8 @@ import { type Layer } from './overlay.js';
|
|
|
7
7
|
import type { HeldEntry, OverlayEntry, StoredEntry } from './tables.js';
|
|
8
8
|
export type ReplicaRecord = {
|
|
9
9
|
readonly locator: string;
|
|
10
|
-
readonly
|
|
11
|
-
readonly handle: string;
|
|
12
|
-
readonly operations: OperationScopes;
|
|
13
|
-
readonly replica: ReplicaAdmission;
|
|
10
|
+
readonly declaration: RoomDeclaration;
|
|
14
11
|
readonly model: ModelState;
|
|
15
|
-
readonly typedSelection: TypedSelection | null;
|
|
16
|
-
readonly providerOwnedPaths: readonly string[];
|
|
17
12
|
readonly roomVersion: string;
|
|
18
13
|
readonly transfer: string;
|
|
19
14
|
readonly inventory: BootstrapInventory;
|
|
@@ -32,7 +27,7 @@ export type Slice = Layer & {
|
|
|
32
27
|
readonly facts: Readonly<Record<string, SavedFacts>>;
|
|
33
28
|
readonly held: ReadonlySet<string>;
|
|
34
29
|
};
|
|
35
|
-
export declare function compositionOf(
|
|
30
|
+
export declare function compositionOf(model: ModelState, typedSelection: TypedSelection | null, builtIn: ModelState, typedPaths: readonly TypedPath[]): Composition;
|
|
36
31
|
export declare function storedRecord(record: ReplicaRecord): string;
|
|
37
32
|
export declare function slicing(entries: readonly HeldEntry[], paths: Iterable<string>): Generator<number, Slice, void>;
|
|
38
33
|
export type LayerEntry = Omit<StoredEntry, 'facts'>;
|
|
@@ -48,8 +43,8 @@ export type Replayed = {
|
|
|
48
43
|
};
|
|
49
44
|
export declare function replaying(confirmed: Slice, queue: readonly ChangeBatch[], locator: string, composition: Composition): Generator<number, Replayed, void>;
|
|
50
45
|
export declare function overlayOf(visible: VisibleLayer, touched: Iterable<string>): Generator<number, OverlayEntry[], void>;
|
|
51
|
-
export declare function holds(layer: Layer, preconditions: readonly Precondition[]): boolean;
|
|
52
|
-
export declare function landed(batch: ChangeBatch, confirmed: Layer, current?: Readonly<Record<string, string>>): boolean;
|
|
46
|
+
export declare function holds(layer: Layer, preconditions: readonly Precondition[], composition: Composition): boolean;
|
|
47
|
+
export declare function landed(batch: ChangeBatch, confirmed: Layer, composition: Composition, current?: Readonly<Record<string, string>>): boolean;
|
|
53
48
|
export type Standing = {
|
|
54
49
|
readonly withdrawn: readonly ChangeBatch[];
|
|
55
50
|
readonly kept: readonly ChangeBatch[];
|
package/dist/replica.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replica.d.ts","sourceRoot":"","sources":["../src/replica.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,KAAK,EACV,kBAAkB,EAClB,UAAU,EAEV,cAAc,EACd,eAAe,EACf,
|
|
1
|
+
{"version":3,"file":"replica.d.ts","sourceRoot":"","sources":["../src/replica.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,KAAK,EACV,kBAAkB,EAClB,UAAU,EAEV,cAAc,EACd,eAAe,EACf,cAAc,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAKL,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAA+B,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACjG,OAAO,EAAe,KAAK,U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SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,CAiBrF;AAED,wBAAiB,SAAS,CACxB,SAAS,EAAE,KAAK,EAChB,SAAS,EAAE,WAAW,EACtB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,WAAW,GACvB,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CA6FnC"}
|
package/dist/replica.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { equalValue, parse } from '@agentshouse/mdmodel';
|
|
2
|
-
import { immutable, landing } from './change.js';
|
|
3
|
-
import { collectionOf } from './collection.js';
|
|
2
|
+
import { immutable, isPart, landing, } from './change.js';
|
|
3
|
+
import { collectionOf, definitionsAt } from './collection.js';
|
|
4
4
|
import { storedModel } from './model.js';
|
|
5
5
|
import { acceptedBinaries, overlaying } from './overlay.js';
|
|
6
6
|
import { writtenFacts } from './rows.js';
|
|
7
7
|
import { effectiveIn, rewriting } from './save.js';
|
|
8
|
+
import { guarding } from './shared.js';
|
|
8
9
|
import { ROW_WEIGHT } from './turn.js';
|
|
9
|
-
export function compositionOf(
|
|
10
|
+
export function compositionOf(model, typedSelection, builtIn, typedPaths) {
|
|
10
11
|
return {
|
|
11
|
-
model
|
|
12
|
-
selection:
|
|
13
|
-
? null
|
|
14
|
-
: { roots: record.typedSelection.roots, model: builtIn },
|
|
12
|
+
model,
|
|
13
|
+
selection: typedSelection === null ? null : { roots: typedSelection.roots, model: builtIn },
|
|
15
14
|
typedPaths,
|
|
16
15
|
};
|
|
17
16
|
}
|
|
@@ -37,7 +36,7 @@ function strict(values, held) {
|
|
|
37
36
|
throw new UnreadPath(property);
|
|
38
37
|
}
|
|
39
38
|
};
|
|
40
|
-
return
|
|
39
|
+
return guarding(values, {
|
|
41
40
|
get(target, property, receiver) {
|
|
42
41
|
guard(property);
|
|
43
42
|
return Reflect.get(target, property, receiver);
|
|
@@ -170,7 +169,7 @@ export function* replaying(confirmed, queue, locator, composition) {
|
|
|
170
169
|
for (const change of effective.changes)
|
|
171
170
|
for (const path of changePaths(change))
|
|
172
171
|
touched.add(path);
|
|
173
|
-
layer = yield* overlaying(layer, [effective]);
|
|
172
|
+
layer = yield* overlaying(layer, [effective], composition);
|
|
174
173
|
yield ROW_WEIGHT;
|
|
175
174
|
}
|
|
176
175
|
return {
|
|
@@ -209,12 +208,12 @@ export function* overlayOf(visible, touched) {
|
|
|
209
208
|
function present(layer, path) {
|
|
210
209
|
return layer.documents[path] !== undefined || layer.binaries[path] !== undefined;
|
|
211
210
|
}
|
|
212
|
-
export function holds(layer, preconditions) {
|
|
211
|
+
export function holds(layer, preconditions, composition) {
|
|
213
212
|
const parsed = new Map();
|
|
214
213
|
const documentAt = (path) => {
|
|
215
214
|
if (!parsed.has(path)) {
|
|
216
215
|
const text = layer.documents[path];
|
|
217
|
-
const opened = text === undefined ? null : parse(text, path);
|
|
216
|
+
const opened = text === undefined ? null : parse(text, path, definitionsAt(composition, path));
|
|
218
217
|
parsed.set(path, opened?.ok === true ? opened.document : null);
|
|
219
218
|
}
|
|
220
219
|
return parsed.get(path) ?? null;
|
|
@@ -248,7 +247,7 @@ export function holds(layer, preconditions) {
|
|
|
248
247
|
}
|
|
249
248
|
function effects(change) {
|
|
250
249
|
const path = change.path;
|
|
251
|
-
if (change
|
|
250
|
+
if (isPart(change)) {
|
|
252
251
|
return [change];
|
|
253
252
|
}
|
|
254
253
|
if (change.kind === 'create' && !('content' in change)) {
|
|
@@ -274,11 +273,11 @@ function effects(change) {
|
|
|
274
273
|
{ kind: 'present', path: change.to },
|
|
275
274
|
];
|
|
276
275
|
}
|
|
277
|
-
if (change.kind === '
|
|
276
|
+
if (change.kind === 'arrival')
|
|
278
277
|
return [{ kind: 'present', path }];
|
|
279
278
|
return [{ kind: 'absent', path }];
|
|
280
279
|
}
|
|
281
|
-
export function landed(batch, confirmed, current = {}) {
|
|
280
|
+
export function landed(batch, confirmed, composition, current = {}) {
|
|
282
281
|
const documents = new Proxy(confirmed.documents, {
|
|
283
282
|
get(target, property, receiver) {
|
|
284
283
|
if (typeof property === 'string' && Object.hasOwn(current, property))
|
|
@@ -298,9 +297,9 @@ export function landed(batch, confirmed, current = {}) {
|
|
|
298
297
|
}
|
|
299
298
|
return effects(change).every((effect) => {
|
|
300
299
|
if (effect.kind === 'absent')
|
|
301
|
-
return holds(layer, [effect]);
|
|
300
|
+
return holds(layer, [effect], composition);
|
|
302
301
|
const at = landing(batch.changes, index, effect.path);
|
|
303
|
-
return at === null || holds(layer, [{ ...effect, path: at }]);
|
|
302
|
+
return at === null || holds(layer, [{ ...effect, path: at }], composition);
|
|
304
303
|
});
|
|
305
304
|
});
|
|
306
305
|
}
|
|
@@ -325,7 +324,7 @@ export function* standing(confirmed, queue, withdrawable, local, locator, compos
|
|
|
325
324
|
const withdrawn = [];
|
|
326
325
|
const kept = [];
|
|
327
326
|
for (const batch of queue) {
|
|
328
|
-
if (withdrawable(batch) && !holds(layer, batch.preconditions)) {
|
|
327
|
+
if (withdrawable(batch) && !holds(layer, batch.preconditions, composition)) {
|
|
329
328
|
withdrawn.push(batch);
|
|
330
329
|
continue;
|
|
331
330
|
}
|
|
@@ -336,7 +335,7 @@ export function* standing(confirmed, queue, withdrawable, local, locator, compos
|
|
|
336
335
|
})
|
|
337
336
|
: batch;
|
|
338
337
|
let unapplied = false;
|
|
339
|
-
const next = yield* overlaying(layer, [effective], () => {
|
|
338
|
+
const next = yield* overlaying(layer, [effective], composition, () => {
|
|
340
339
|
unapplied = true;
|
|
341
340
|
});
|
|
342
341
|
if (local && unapplied) {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type RuntimeShell } from './durability.js';
|
|
2
|
+
export declare const STEPS: readonly ['database', 'sign_in', 'connection', 'code', 'download', 'conversations', 'sending', 'reading'];
|
|
3
|
+
export type Step = (typeof STEPS)[number];
|
|
4
|
+
export type RetriedFailure = {
|
|
5
|
+
readonly step: Step;
|
|
6
|
+
readonly answered: false;
|
|
7
|
+
} | {
|
|
8
|
+
readonly step: Step;
|
|
9
|
+
readonly answered: true;
|
|
10
|
+
readonly error: unknown;
|
|
11
|
+
};
|
|
12
|
+
export type Uncertain = {
|
|
13
|
+
readonly failure?: unknown;
|
|
14
|
+
};
|
|
15
|
+
export type Attempt = {
|
|
16
|
+
readonly step: Step;
|
|
17
|
+
readonly instance: string;
|
|
18
|
+
};
|
|
19
|
+
export declare class Unanswered extends Error {
|
|
20
|
+
}
|
|
21
|
+
export declare function uncertainError(uncertainty: Uncertain): unknown;
|
|
22
|
+
export type Retries = {
|
|
23
|
+
failed(step: Step, instance: string, error: unknown): void;
|
|
24
|
+
unanswered(step: Step, instance: string): void;
|
|
25
|
+
uncertain(step: Step, instance: string, uncertainty: Uncertain): void;
|
|
26
|
+
succeeded(step: Step, instance: string): void;
|
|
27
|
+
};
|
|
28
|
+
export declare function createRetries(shell: Pick<RuntimeShell, 'retried' | 'succeeded'>): Retries;
|
|
29
|
+
export declare function retrying<T>(retries: Retries, step: Step, instance: string, ask: () => Promise<T>): () => Promise<T>;
|
|
30
|
+
//# sourceMappingURL=retried.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retried.d.ts","sourceRoot":"","sources":["../src/retried.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAErE,eAAO,MAAM,KAAK,YAChB,UAAU,EACV,SAAS,EACT,YAAY,EACZ,MAAM,EACN,UAAU,EACV,eAAe,EACf,SAAS,EACT,SAAS,CACD,CAAC;AAEX,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1C,MAAM,MAAM,cAAc,GACtB;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAA;CAAE,GACjD;IA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
1
|
+
import { refusedForSpace } from './durability.js';
|
|
2
|
+
export const STEPS = [
|
|
3
|
+
'database',
|
|
4
|
+
'sign_in',
|
|
5
|
+
'connection',
|
|
6
|
+
'code',
|
|
7
|
+
'download',
|
|
8
|
+
'conversations',
|
|
9
|
+
'sending',
|
|
10
|
+
'reading',
|
|
11
|
+
];
|
|
12
|
+
export class Unanswered extends Error {
|
|
13
|
+
}
|
|
14
|
+
export function uncertainError(uncertainty) {
|
|
15
|
+
return 'failure' in uncertainty ? uncertainty.failure : new Unanswered();
|
|
16
|
+
}
|
|
17
|
+
export function createRetries(shell) {
|
|
18
|
+
const failing = new Map();
|
|
19
|
+
const handedErrors = new WeakSet();
|
|
20
|
+
function failingIn(step, instance) {
|
|
21
|
+
const instances = failing.get(step) ?? new Set();
|
|
22
|
+
instances.add(instance);
|
|
23
|
+
failing.set(step, instances);
|
|
24
|
+
}
|
|
25
|
+
function handed(failure, instance) {
|
|
26
|
+
failingIn(failure.step, instance);
|
|
27
|
+
shell.retried?.(failure);
|
|
28
|
+
}
|
|
29
|
+
const retries = {
|
|
30
|
+
failed(step, instance, error) {
|
|
31
|
+
if (refusedForSpace(error))
|
|
32
|
+
return;
|
|
33
|
+
if (typeof error === 'object' && error !== null) {
|
|
34
|
+
if (handedErrors.has(error)) {
|
|
35
|
+
failingIn(step, instance);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
handedErrors.add(error);
|
|
39
|
+
}
|
|
40
|
+
if (error instanceof Unanswered)
|
|
41
|
+
retries.unanswered(step, instance);
|
|
42
|
+
else
|
|
43
|
+
handed({ step, answered: true, error }, instance);
|
|
44
|
+
},
|
|
45
|
+
unanswered(step, instance) {
|
|
46
|
+
handed({ step, answered: false }, instance);
|
|
47
|
+
},
|
|
48
|
+
uncertain(step, instance, uncertainty) {
|
|
49
|
+
if ('failure' in uncertainty)
|
|
50
|
+
retries.failed(step, instance, uncertainty.failure);
|
|
51
|
+
else
|
|
52
|
+
retries.unanswered(step, instance);
|
|
53
|
+
},
|
|
54
|
+
succeeded(step, instance) {
|
|
55
|
+
const instances = failing.get(step);
|
|
56
|
+
if (instances === undefined || !instances.delete(instance) || instances.size > 0)
|
|
57
|
+
return;
|
|
58
|
+
failing.delete(step);
|
|
59
|
+
shell.succeeded?.(step);
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
return retries;
|
|
63
|
+
}
|
|
64
|
+
export function retrying(retries, step, instance, ask) {
|
|
65
|
+
return () => ask().then((answer) => {
|
|
66
|
+
retries.succeeded(step, instance);
|
|
67
|
+
return answer;
|
|
68
|
+
}, (error) => {
|
|
69
|
+
retries.failed(step, instance, error);
|
|
70
|
+
throw error;
|
|
71
|
+
});
|
|
72
|
+
}
|