@listen-fire/engine 0.13.0 → 0.13.1
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/dist/services/embed/in_process_host.js +10 -1
- package/dist/services/inbound/contract.js +3 -3
- package/dist/services/inbound/deliver.d.ts +2 -1
- package/dist/services/inbound/deliver.js +3 -1
- package/dist/services/loop_guard/contract.js +7 -50
- package/dist/services/loop_guard/loop_guard.d.ts +0 -22
- package/dist/services/loop_guard/loop_guard.js +10 -26
- package/dist/services/loop_guard/rpc_loop_guard.d.ts +1 -2
- package/dist/services/loop_guard/rpc_loop_guard.js +0 -4
- package/dist/services/translation_graph/engine/adapter_table.d.ts +6 -0
- package/dist/services/translation_graph/engine/adapter_table.js +8 -0
- package/dist/services/translation_graph/movement/catalog_snapshot.d.ts +4 -0
- package/dist/services/translation_graph/movement/catalog_snapshot.js +1 -0
- package/dist/services/translation_graph/triggers/listen_plans.d.ts +10 -6
- package/dist/services/translation_graph/triggers/listen_plans.js +20 -13
- package/dist/services/translation_graph/triggers/trigger_event.d.ts +2 -0
- package/dist/services/translation_graph/triggers/trigger_event.js +2 -0
- package/package.json +4 -4
|
@@ -92,7 +92,16 @@ function inProcessHost(options = {}) {
|
|
|
92
92
|
return (0, host_kit_1.actingPrincipalOf)(await resolve({
|
|
93
93
|
teamId: segments.facts(segmentId).teamId,
|
|
94
94
|
...(triggerId !== undefined ? { triggerId } : {}),
|
|
95
|
-
|
|
95
|
+
// The module's own candidates where it offers them (an API lookup,
|
|
96
|
+
// a mail's relays); else who acted on the arrival, as its module
|
|
97
|
+
// said at the door (adapter protocol 2.7).
|
|
98
|
+
getCandidates: async () => {
|
|
99
|
+
if (table.offers({ segmentId, instance, method: 'getActorCandidates' })) {
|
|
100
|
+
return table.answer({ segmentId, instance, method: 'getActorCandidates', args: { event } });
|
|
101
|
+
}
|
|
102
|
+
const actor = event.arrival?.actor;
|
|
103
|
+
return actor === undefined ? [] : [{ identity: actor, source: 'originator' }];
|
|
104
|
+
},
|
|
96
105
|
}));
|
|
97
106
|
},
|
|
98
107
|
},
|
|
@@ -210,11 +210,11 @@ exports.INBOUND_CONTRACT_CASES = [
|
|
|
210
210
|
},
|
|
211
211
|
},
|
|
212
212
|
{
|
|
213
|
-
name: 'arrivals are logged whether or not any event came with them',
|
|
213
|
+
name: 'arrivals are logged whether or not any event came with them, and counted in the acknowledgement',
|
|
214
214
|
async run(backend) {
|
|
215
215
|
await arrangeAnd(backend);
|
|
216
216
|
const answer = await post(backend, CRM_DOOR, json({ arrivals: [ARRIVAL, GONE] }), crmSigned);
|
|
217
|
-
strict_1.default.deepEqual([answer.status, answer.body], [200, { ok: true, eventsProcessed:
|
|
217
|
+
strict_1.default.deepEqual([answer.status, answer.body], [200, { ok: true, eventsProcessed: 2 }]);
|
|
218
218
|
strict_1.default.deepEqual((await backend.observed()).arrivals, [ARRIVAL, GONE]);
|
|
219
219
|
},
|
|
220
220
|
},
|
|
@@ -246,7 +246,7 @@ exports.INBOUND_CONTRACT_CASES = [
|
|
|
246
246
|
strict_1.default.deepEqual([failed.status, failed.body], [500, { error: 'internal' }]);
|
|
247
247
|
strict_1.default.deepEqual((await backend.observed()).arrivals, []);
|
|
248
248
|
const retried = await post(backend, CRM_DOOR, delivery, crmSigned);
|
|
249
|
-
strict_1.default.deepEqual([retried.status, retried.body], [200, { ok: true, eventsProcessed:
|
|
249
|
+
strict_1.default.deepEqual([retried.status, retried.body], [200, { ok: true, eventsProcessed: 3 }]);
|
|
250
250
|
const seen = await backend.observed();
|
|
251
251
|
strict_1.default.deepEqual([seen.enqueued, seen.arrivals], [2, [ARRIVAL]]);
|
|
252
252
|
},
|
|
@@ -130,7 +130,8 @@ export type ReceivedDelivery<Captured> = {
|
|
|
130
130
|
reply: InboundAnswer;
|
|
131
131
|
} | {
|
|
132
132
|
ok: true;
|
|
133
|
-
/**
|
|
133
|
+
/** What the delivery brought: the events captured (receipted and
|
|
134
|
+
* ready to run) and the arrivals it reported. */
|
|
134
135
|
eventsProcessed: number;
|
|
135
136
|
/** The delivery's one write, made before the ack. Absent when the
|
|
136
137
|
* delivery carried nothing to run or log. Rejects when it could not
|
|
@@ -118,7 +118,9 @@ async function receiveDelivery(store, delivery) {
|
|
|
118
118
|
};
|
|
119
119
|
return {
|
|
120
120
|
ok: true,
|
|
121
|
-
|
|
121
|
+
// A module reports arrivals since 0.13: counting its events alone
|
|
122
|
+
// answered 0 for every delivery.
|
|
123
|
+
eventsProcessed: captured.length + arrivals.length,
|
|
122
124
|
queue,
|
|
123
125
|
...(store.verifiesSignature(subscription) ? {} : { drainFirst: true }),
|
|
124
126
|
...(replyOnceKept !== undefined ? { replyOnceKept } : {}),
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// to — the built-in in this process (FingerprintGuard), listen-fire's Rust one over
|
|
4
4
|
// the guard wire (`listen-fire --contract-guard`, a file and a Postgres database), and
|
|
5
5
|
// a guard module listen-fire drives as a process (`listen-fire --contract-guard-slot`), all in
|
|
6
|
-
// apps/cli's tests.
|
|
7
|
-
//
|
|
6
|
+
// apps/cli's tests. A guard is only told of writes, so each case holds it to
|
|
7
|
+
// taking them; what it remembers, and for how long, is its own business.
|
|
8
8
|
//
|
|
9
9
|
// Runner-agnostic, as the run host's suite is: each case is a name and an
|
|
10
10
|
// async body that throws on failure (node:assert). Every case uses records
|
|
@@ -22,69 +22,26 @@ function aRecord() {
|
|
|
22
22
|
}
|
|
23
23
|
const seen = { name: 'Acme', description: 'Seen by lf' };
|
|
24
24
|
const edited = { name: 'Acme', description: 'Edited by Bob' };
|
|
25
|
-
async function isEcho(guard, question) {
|
|
26
|
-
return guard.isEcho(question);
|
|
27
|
-
}
|
|
28
25
|
exports.loopGuardContractCases = [
|
|
29
26
|
{
|
|
30
|
-
name: 'a
|
|
31
|
-
async run(guard) {
|
|
32
|
-
const { adapter, externalId } = aRecord();
|
|
33
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: WRITER }), { echo: false });
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: 'a written record asks to be read, and unchanged is the writer\'s echo',
|
|
38
|
-
async run(guard) {
|
|
39
|
-
const one = aRecord();
|
|
40
|
-
await guard.recordWrite({ ...one, writer: WRITER, record: seen });
|
|
41
|
-
const { adapter, externalId } = one;
|
|
42
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: WRITER }), { read: { recordType: 'Companies' } });
|
|
43
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: WRITER, current: { recordType: 'Companies', record: structuredClone(seen) } }), { echo: true });
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
name: 'a record changed since the write is not an echo',
|
|
27
|
+
name: 'a write is taken, and answers nothing',
|
|
48
28
|
async run(guard) {
|
|
49
|
-
|
|
50
|
-
await guard.recordWrite({ ...one, writer: WRITER, record: seen });
|
|
51
|
-
const { adapter, externalId } = one;
|
|
52
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: WRITER, current: { recordType: 'Companies', record: edited } }), { echo: false });
|
|
29
|
+
strict_1.default.equal(await guard.recordWrite({ ...aRecord(), writer: WRITER, record: seen }), undefined);
|
|
53
30
|
},
|
|
54
31
|
},
|
|
55
32
|
{
|
|
56
|
-
name: '
|
|
33
|
+
name: 'a write that left the record gone is taken',
|
|
57
34
|
async run(guard) {
|
|
58
|
-
|
|
59
|
-
await guard.recordWrite({ ...one, writer: WRITER, record: seen });
|
|
60
|
-
const { adapter, externalId } = one;
|
|
61
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: 'listen:audit:log' }), { echo: false });
|
|
62
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId: `${externalId}-other`, writer: WRITER }), { echo: false });
|
|
63
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter: 'airtable', externalId, writer: WRITER }), { echo: false });
|
|
35
|
+
await guard.recordWrite({ ...aRecord(), writer: WRITER, record: null });
|
|
64
36
|
},
|
|
65
37
|
},
|
|
66
38
|
{
|
|
67
|
-
name: '
|
|
39
|
+
name: 'a writer\'s later write to the same record is taken, beside another writer\'s',
|
|
68
40
|
async run(guard) {
|
|
69
41
|
const one = aRecord();
|
|
70
|
-
const { adapter, externalId } = one;
|
|
71
42
|
await guard.recordWrite({ ...one, writer: WRITER, record: seen });
|
|
72
43
|
await guard.recordWrite({ ...one, writer: 'listen:audit:log', record: edited });
|
|
73
44
|
await guard.recordWrite({ ...one, writer: WRITER, record: edited });
|
|
74
|
-
const now = { recordType: 'Companies', record: structuredClone(seen) };
|
|
75
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: WRITER, current: now }), { echo: false });
|
|
76
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: WRITER, current: { ...now, record: edited } }), { echo: true });
|
|
77
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: 'listen:audit:log', current: { ...now, record: edited } }), { echo: true });
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
name: 'a record that is gone can be the echo of its own deletion',
|
|
82
|
-
async run(guard) {
|
|
83
|
-
const one = aRecord();
|
|
84
|
-
const { adapter, externalId } = one;
|
|
85
|
-
await guard.recordWrite({ ...one, writer: WRITER, record: null });
|
|
86
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: WRITER, current: { recordType: 'Companies', record: null } }), { echo: true });
|
|
87
|
-
strict_1.default.deepEqual(await isEcho(guard, { adapter, externalId, writer: WRITER, current: { recordType: 'Companies', record: seen } }), { echo: false });
|
|
88
45
|
},
|
|
89
46
|
},
|
|
90
47
|
];
|
|
@@ -7,30 +7,9 @@ export interface RecordWrite {
|
|
|
7
7
|
writer: string;
|
|
8
8
|
record: unknown;
|
|
9
9
|
}
|
|
10
|
-
/** Whether an event naming `externalId` is the echo of `writer`'s write.
|
|
11
|
-
* `current` is the record as it stands now, sent once the guard has said
|
|
12
|
-
* which type to read. */
|
|
13
|
-
export interface EchoQuestion {
|
|
14
|
-
adapter: string;
|
|
15
|
-
externalId: string;
|
|
16
|
-
writer: string;
|
|
17
|
-
current?: {
|
|
18
|
-
recordType: string;
|
|
19
|
-
record: unknown;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
/** `echo`: the answer. `read`: the guard needs `current` of this type to say. */
|
|
23
|
-
export type EchoAnswer = {
|
|
24
|
-
echo: boolean;
|
|
25
|
-
} | {
|
|
26
|
-
read: {
|
|
27
|
-
recordType: string;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
10
|
export interface LoopGuard {
|
|
31
11
|
/** `writer`'s write, remembered; its later write to the same record replaces it. */
|
|
32
12
|
recordWrite(write: RecordWrite): Promise<void>;
|
|
33
|
-
isEcho(question: EchoQuestion): Promise<EchoAnswer>;
|
|
34
13
|
}
|
|
35
14
|
/** How long the built-in remembers a write. */
|
|
36
15
|
export declare const REMEMBERED_MS = 3600000;
|
|
@@ -38,5 +17,4 @@ export declare const REMEMBERED_MS = 3600000;
|
|
|
38
17
|
export declare class FingerprintGuard implements LoopGuard {
|
|
39
18
|
private readonly remembered;
|
|
40
19
|
recordWrite(write: RecordWrite): Promise<void>;
|
|
41
|
-
isEcho(question: EchoQuestion): Promise<EchoAnswer>;
|
|
42
20
|
}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// The loop guard slot: a module
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// movement that writes to a source it listens to hears its own write come
|
|
6
|
-
// back and runs again. The platform's opt-in `suppress_self` listen flag is
|
|
7
|
-
// separate and unchanged.
|
|
2
|
+
// The loop guard slot: a module told of each record write a run makes
|
|
3
|
+
// (plans/cloud-native-2026-10-06/22_everywhere_plan.md, Henry 2026-10-18).
|
|
4
|
+
// Empty unless a project names one in `core:`.
|
|
8
5
|
//
|
|
9
|
-
// The host reads a record back after a run writes it
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
// (crates/lf/src/loop_guard.rs).
|
|
6
|
+
// The host reads a record back after a run writes it and tells the guard
|
|
7
|
+
// (`recordWrite`). Nothing asks the guard anything back: the host's loop
|
|
8
|
+
// breaker caps every chain of writes and arrivals, and the slot's `isEcho`
|
|
9
|
+
// is retired. The contract is docs/contracts/loop-guard-slot.md; the
|
|
10
|
+
// built-in, `@lf/fingerprint-guard`, is `FingerprintGuard` here and in
|
|
11
|
+
// listen-fire (crates/lf/src/loop_guard.rs).
|
|
16
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
13
|
exports.FingerprintGuard = exports.REMEMBERED_MS = void 0;
|
|
18
14
|
const node_crypto_1 = require("node:crypto");
|
|
@@ -29,19 +25,7 @@ class FingerprintGuard {
|
|
|
29
25
|
for (const [key, one] of this.remembered)
|
|
30
26
|
if (one.expiresAt <= now)
|
|
31
27
|
this.remembered.delete(key);
|
|
32
|
-
this.remembered.set(JSON.stringify([write.adapter, write.externalId, write.writer]), {
|
|
33
|
-
recordType: write.recordType,
|
|
34
|
-
fingerprint: fingerprint(write.record),
|
|
35
|
-
expiresAt: now + exports.REMEMBERED_MS,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
async isEcho(question) {
|
|
39
|
-
const one = this.remembered.get(JSON.stringify([question.adapter, question.externalId, question.writer]));
|
|
40
|
-
if (one === undefined || one.expiresAt <= Date.now())
|
|
41
|
-
return { echo: false };
|
|
42
|
-
if (question.current === undefined)
|
|
43
|
-
return { read: { recordType: one.recordType } };
|
|
44
|
-
return { echo: fingerprint(question.current.record) === one.fingerprint };
|
|
28
|
+
this.remembered.set(JSON.stringify([write.adapter, write.externalId, write.writer]), { fingerprint: fingerprint(write.record), expiresAt: now + exports.REMEMBERED_MS });
|
|
45
29
|
}
|
|
46
30
|
}
|
|
47
31
|
exports.FingerprintGuard = FingerprintGuard;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SlotAddress } from '@listen-fire/module-runtime/module_wire/wire';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LoopGuard, RecordWrite } from './loop_guard';
|
|
3
3
|
export declare class RpcLoopGuard implements LoopGuard {
|
|
4
4
|
private readonly started;
|
|
5
5
|
/** The guard module `command` starts, or the one already at `address`. */
|
|
@@ -8,6 +8,5 @@ export declare class RpcLoopGuard implements LoopGuard {
|
|
|
8
8
|
private call;
|
|
9
9
|
open(settings?: Record<string, string>): Promise<void>;
|
|
10
10
|
recordWrite(write: RecordWrite): Promise<void>;
|
|
11
|
-
isEcho(question: EchoQuestion): Promise<EchoAnswer>;
|
|
12
11
|
close(): Promise<void>;
|
|
13
12
|
}
|
|
@@ -8,7 +8,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
8
|
exports.RpcLoopGuard = void 0;
|
|
9
9
|
const zod_1 = require("zod");
|
|
10
10
|
const wire_1 = require("@listen-fire/module-runtime/module_wire/wire");
|
|
11
|
-
const Answer = zod_1.z.union([zod_1.z.object({ echo: zod_1.z.boolean() }), zod_1.z.object({ read: zod_1.z.object({ recordType: zod_1.z.string() }) })]);
|
|
12
11
|
const Nothing = zod_1.z.null();
|
|
13
12
|
class RpcLoopGuard {
|
|
14
13
|
started;
|
|
@@ -28,9 +27,6 @@ class RpcLoopGuard {
|
|
|
28
27
|
async recordWrite(write) {
|
|
29
28
|
await this.call('guard.recordWrite', write, Nothing);
|
|
30
29
|
}
|
|
31
|
-
isEcho(question) {
|
|
32
|
-
return this.call('guard.isEcho', question, Answer);
|
|
33
|
-
}
|
|
34
30
|
async close() {
|
|
35
31
|
await (await this.started.catch(() => undefined))?.close();
|
|
36
32
|
}
|
|
@@ -36,6 +36,12 @@ export interface AdapterTable extends HostAdapters {
|
|
|
36
36
|
/** A call the host makes itself (the acting-user lookup asks the source
|
|
37
37
|
* instance for the event's actors): its result, or its failure thrown. */
|
|
38
38
|
answer<M extends AdapterMethod>(input: AdapterCall<M>): Promise<AdapterCallMap[M]['result']>;
|
|
39
|
+
/** Whether an instance the segment holds offers `method`. */
|
|
40
|
+
offers(input: {
|
|
41
|
+
segmentId: string;
|
|
42
|
+
instance: string;
|
|
43
|
+
method: AdapterMethod;
|
|
44
|
+
}): boolean;
|
|
39
45
|
/** Forget a segment's instances once the segment has closed. */
|
|
40
46
|
closeSegment(segmentId: string): void;
|
|
41
47
|
/** The instances a segment holds, as a file's owner is found among them. */
|
|
@@ -174,6 +174,10 @@ class SegmentInstances {
|
|
|
174
174
|
(owner.constructionArgs === undefined || args(resolution.constructionArgs) === args(owner.constructionArgs)));
|
|
175
175
|
return matching.length === 1 ? matching[0]?.adapter : undefined;
|
|
176
176
|
}
|
|
177
|
+
/** The instance resolved as `id`, if it was. */
|
|
178
|
+
found(id) {
|
|
179
|
+
return this.byId.get(id);
|
|
180
|
+
}
|
|
177
181
|
instance(id) {
|
|
178
182
|
const adapter = this.byId.get(id);
|
|
179
183
|
if (adapter === undefined) {
|
|
@@ -259,6 +263,10 @@ function adapterTable(options) {
|
|
|
259
263
|
});
|
|
260
264
|
},
|
|
261
265
|
call,
|
|
266
|
+
offers({ segmentId, instance, method }) {
|
|
267
|
+
const adapter = instances.get(segmentId)?.found(instance);
|
|
268
|
+
return adapter !== undefined && typeof Reflect.get(adapter, method) === 'function';
|
|
269
|
+
},
|
|
262
270
|
async answer(input) {
|
|
263
271
|
const answered = await call(input);
|
|
264
272
|
if ('error' in answered)
|
|
@@ -26,6 +26,10 @@ export interface CatalogAdapterInput {
|
|
|
26
26
|
/** How the adapter is connected — a product-shell fact (the hosted product's
|
|
27
27
|
* connect links); absent where the shell has no such affordance. */
|
|
28
28
|
connect?: AdapterSpec['connect'];
|
|
29
|
+
/** The package the host installed the module from (`@lf/github`), which a
|
|
30
|
+
* program's `connect` names it by; absent for a host's own module, named
|
|
31
|
+
* `#` and its adapter type. */
|
|
32
|
+
package?: string;
|
|
29
33
|
/** Instance schemas by `instanceSchemaKey`; absent ⇒ none introspected yet. */
|
|
30
34
|
schemas?: Record<string, InstanceSchema>;
|
|
31
35
|
/** Why a schema is missing, keyed like `schemas`. */
|
|
@@ -56,6 +56,7 @@ function adapterSnapshotOf(input) {
|
|
|
56
56
|
.map((b) => ({ kind: b.actionKind, label: b.label }));
|
|
57
57
|
return {
|
|
58
58
|
constructionArgs: input.constructionArgs ?? constructionArgsOf(manifest),
|
|
59
|
+
...(input.package !== undefined ? { package: input.package } : {}),
|
|
59
60
|
...(manifest.declaredCredentials !== undefined ? { declaredCredentials: [...manifest.declaredCredentials] } : {}),
|
|
60
61
|
// A construction-free manifest fact: an adapter that names no trigger
|
|
61
62
|
// type has no inbound surface to listen to. Only `true` projects — see
|
|
@@ -131,18 +131,19 @@ export declare function namedArrival(arrival: Exclude<Arrival, {
|
|
|
131
131
|
}>;
|
|
132
132
|
/** The edges a fired function waits on off the records its run is handed at
|
|
133
133
|
* delivery: off the trigger itself (`own`), and off each record the
|
|
134
|
-
* arrival carries,
|
|
134
|
+
* arrival carries, by the record type it states (`carried`): an arrival
|
|
135
|
+
* that fires carries each record of the type its hop lands on, whichever
|
|
136
|
+
* member of a union it is under. */
|
|
135
137
|
export interface TriggerAwaits {
|
|
136
138
|
own: string[];
|
|
137
|
-
carried: string[]
|
|
139
|
+
carried: Readonly<Record<string, readonly string[]>>;
|
|
138
140
|
}
|
|
139
141
|
/** The edges the check stamps on the parameter of the function `plan` fires,
|
|
140
142
|
* which `program` declares: where a run of it enters its trigger, and so
|
|
141
143
|
* the waits a delivery opens for the run as it is kept
|
|
142
144
|
* (crates/lf/src/routing.rs `trigger_awaits_of`). Those awaited off the
|
|
143
145
|
* trigger (`opensWaits`), and off each record type the arrival carries
|
|
144
|
-
* (`carriedAwaits`),
|
|
145
|
-
* carried hop lands on. `stamps` is the check's of `program`. */
|
|
146
|
+
* (`carriedAwaits`), by that type. `stamps` is the check's of `program`. */
|
|
146
147
|
export declare function triggerAwaitsOf(input: {
|
|
147
148
|
program: Program;
|
|
148
149
|
stamps: CheckAnswer['stamps'];
|
|
@@ -155,8 +156,11 @@ export declare function arrivalReceiptKey(arrival: Exclude<Arrival, {
|
|
|
155
156
|
gone: true;
|
|
156
157
|
}>): string;
|
|
157
158
|
/** The event a run fired by an arrival is handed: what landed on the
|
|
158
|
-
* listen's last edge, which its function's parameter binds,
|
|
159
|
-
*
|
|
159
|
+
* listen's last edge, which its function's parameter binds, what it carries,
|
|
160
|
+
* what it is about and who acted; stamped with when it happened at its
|
|
161
|
+
* provider, else `now`, so the run's writes say when the change they follow
|
|
162
|
+
* happened (crates/lf/src/routing.rs `arrival_trigger_of`; both read
|
|
163
|
+
* engine-contracts/conformance/arrival-triggers.json). */
|
|
160
164
|
export declare function arrivalTriggerOf(input: {
|
|
161
165
|
pipelineInputId: string;
|
|
162
166
|
adapterType: string;
|
|
@@ -169,7 +169,7 @@ function plannedListensOf(input) {
|
|
|
169
169
|
*/
|
|
170
170
|
function listenFires(listen, arrival, delivery, nowMs) {
|
|
171
171
|
const { plan } = listen;
|
|
172
|
-
if ('gone' in arrival || plan.adapter !== delivery.adapterType ||
|
|
172
|
+
if ('gone' in arrival || plan.adapter !== delivery.adapterType || (0, engine_contracts_1.lastEdgeOf)(plan) !== arrival.edge)
|
|
173
173
|
return null;
|
|
174
174
|
if (!(0, listen_config_1.listenHearsCredential)(listen.credentialName, delivery.credentialName) || arrival.notFor === listen.pipeline)
|
|
175
175
|
return null;
|
|
@@ -241,22 +241,17 @@ function arrivedRecord(landing) {
|
|
|
241
241
|
* the waits a delivery opens for the run as it is kept
|
|
242
242
|
* (crates/lf/src/routing.rs `trigger_awaits_of`). Those awaited off the
|
|
243
243
|
* trigger (`opensWaits`), and off each record type the arrival carries
|
|
244
|
-
* (`carriedAwaits`),
|
|
245
|
-
* carried hop lands on. `stamps` is the check's of `program`. */
|
|
244
|
+
* (`carriedAwaits`), by that type. `stamps` is the check's of `program`. */
|
|
246
245
|
function triggerAwaitsOf(input) {
|
|
247
246
|
const { plan } = input;
|
|
248
247
|
const index = input.program.statements.findIndex((statement) => statement.kind === 'movement' && statement.name === plan.movement);
|
|
249
248
|
if (index === -1)
|
|
250
|
-
return { own: [], carried:
|
|
249
|
+
return { own: [], carried: {} };
|
|
251
250
|
const path = `/statements/${index}/params/0`;
|
|
252
251
|
const onParam = input.stamps.filter((stamp) => stamp.file === undefined && stamp.path === path);
|
|
253
252
|
// The parameter's one stamp of each, as listen-fire reads them (`trigger_awaits_of`).
|
|
254
253
|
const own = onParam.flatMap((stamp) => ('opensWaits' in stamp ? [[...stamp.opensWaits]] : []))[0] ?? [];
|
|
255
|
-
const
|
|
256
|
-
const carried = (plan.carries ?? []).map((edge) => {
|
|
257
|
-
const landed = plan.hops.find((hop) => hop.edge === edge)?.to;
|
|
258
|
-
return landed === undefined ? [] : [...(byType[landed] ?? [])];
|
|
259
|
-
});
|
|
254
|
+
const carried = onParam.flatMap((stamp) => ('carriedAwaits' in stamp ? [stamp.carriedAwaits] : []))[0] ?? {};
|
|
260
255
|
return { own, carried };
|
|
261
256
|
}
|
|
262
257
|
/** The receipt a listen takes of `arrival` as it runs it, so a redelivery
|
|
@@ -266,15 +261,27 @@ function arrivalReceiptKey(arrival) {
|
|
|
266
261
|
return `${arrival.edge}:${arrival.key ?? ''}:${arrival.identity}:${arrival.version ?? ''}`;
|
|
267
262
|
}
|
|
268
263
|
/** The event a run fired by an arrival is handed: what landed on the
|
|
269
|
-
* listen's last edge, which its function's parameter binds,
|
|
270
|
-
*
|
|
264
|
+
* listen's last edge, which its function's parameter binds, what it carries,
|
|
265
|
+
* what it is about and who acted; stamped with when it happened at its
|
|
266
|
+
* provider, else `now`, so the run's writes say when the change they follow
|
|
267
|
+
* happened (crates/lf/src/routing.rs `arrival_trigger_of`; both read
|
|
268
|
+
* engine-contracts/conformance/arrival-triggers.json). */
|
|
271
269
|
function arrivalTriggerOf(input) {
|
|
272
270
|
const { adapterType, arrival } = input;
|
|
271
|
+
const occurred = arrival.occurredAt === undefined ? undefined : new Date(arrival.occurredAt);
|
|
272
|
+
const occurredAt = occurred !== undefined && !Number.isNaN(occurred.getTime()) ? occurred : input.now;
|
|
273
273
|
return {
|
|
274
274
|
pipelineInputId: input.pipelineInputId,
|
|
275
275
|
adapterType,
|
|
276
276
|
triggerType: 'arrival',
|
|
277
|
-
arrival: {
|
|
278
|
-
|
|
277
|
+
arrival: {
|
|
278
|
+
adapterType,
|
|
279
|
+
edge: arrival.edge,
|
|
280
|
+
landing: arrival.landing,
|
|
281
|
+
...(arrival.parents !== undefined && arrival.parents.length > 0 ? { parents: arrival.parents } : {}),
|
|
282
|
+
...(arrival.about !== undefined ? { about: arrival.about } : {}),
|
|
283
|
+
...(arrival.actor !== undefined ? { actor: arrival.actor } : {}),
|
|
284
|
+
},
|
|
285
|
+
occurredAt: occurredAt.toISOString(),
|
|
279
286
|
};
|
|
280
287
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { DiscriminableEvent, EventType } from '../adapter';
|
|
2
2
|
import type { TriggerType } from '@listen-fire/engine-contracts/mutation_context';
|
|
3
3
|
import type { TriggerEvent } from './types';
|
|
4
|
+
/** @deprecated The 0.12 trigger, which no 0.13 host makes: build a run's
|
|
5
|
+
* event with `arrivalTriggerOf` (listen_plans.ts). Removed in 0.14.0. */
|
|
4
6
|
export declare function triggerEventOf(input: {
|
|
5
7
|
pipelineInputId: string;
|
|
6
8
|
adapterType: string;
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.triggerEventOf = triggerEventOf;
|
|
8
8
|
const discriminate_1 = require("../engine/inbound/discriminate");
|
|
9
|
+
/** @deprecated The 0.12 trigger, which no 0.13 host makes: build a run's
|
|
10
|
+
* event with `arrivalTriggerOf` (listen_plans.ts). Removed in 0.14.0. */
|
|
9
11
|
function triggerEventOf(input) {
|
|
10
12
|
const { adapterType, triggerType, event, eventTypes, now } = input;
|
|
11
13
|
let rootRecordType;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@listen-fire/engine",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "0.13.
|
|
4
|
+
"version": "0.13.1",
|
|
5
5
|
"description": "The movement engine for this release's language and its host contract: the Rust engine's shim, the EngineHost families, the run host, the embed kit, and the adapter and model types they reach. Every shell (the hosted product, the `listen-fire` command line, an embedder) runs the same engine. A run pinned to a release this one does not read is refused by name. Embedders reach it only through public/* (the exports map); the internals resolve only under the `movement-engine-internals` condition, which only test runners set",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=22.23.4 <23"
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"safe-stable-stringify": "2.5.0",
|
|
19
19
|
"zod": "4.1.12",
|
|
20
|
-
"@listen-fire/engine-contracts": "^0.13.
|
|
21
|
-
"@listen-fire/
|
|
22
|
-
"@listen-fire/
|
|
20
|
+
"@listen-fire/engine-contracts": "^0.13.1",
|
|
21
|
+
"@listen-fire/movement-lang": "^0.13.1",
|
|
22
|
+
"@listen-fire/module-runtime": "^0.12.8"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/jest": "29.5.14",
|