@listen-fire/engine 0.12.9 → 0.12.11

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.
@@ -119,7 +119,9 @@ exports.limiterContractCases = [
119
119
  name: 'a throttle refuses its key until then, and no other key',
120
120
  async run(limiter) {
121
121
  const throttled = request([]);
122
- const until = Date.now() + 400;
122
+ // Seconds, not milliseconds: over a module's wire the throttle and the
123
+ // acquire are two round trips, which have outlasted a 400 ms window.
124
+ const until = Date.now() + 3_000;
123
125
  await limiter.throttle({ key: throttled.key, until: new Date(until).toISOString() });
124
126
  strict_1.default.ok(refusedUntil(await limiter.acquire(throttled)) >= until - 1, 'refused until the throttle ends');
125
127
  permitOf(await limiter.acquire(request([])));
@@ -313,9 +313,14 @@ export type MovementTraceEntry = {
313
313
  files?: ExtractionTraceFile[];
314
314
  /** How many source files `files` left out at its cap. */
315
315
  filesTruncated?: number;
316
- /** Which model answered, and how long it took (both attempts, when
317
- * the call was retried). */
316
+ /** The tier the call was written with (`null` when it named none),
317
+ * which model answered and how hard it was asked to think, and how
318
+ * long it took (both attempts, when the call was retried). The tiers
319
+ * share a model and differ in effort, so the model alone does not
320
+ * name the tier. */
321
+ tier?: string | null;
318
322
  model?: string;
323
+ effort?: string | null;
319
324
  durationMs?: number;
320
325
  /** Present when the answer came back only because the call was asked
321
326
  * less deeply than its tier says: the first attempt spent its whole
@@ -522,6 +527,11 @@ export type MovementTraceEntry = {
522
527
  kind: 'ai';
523
528
  prompt: string;
524
529
  hasValue: boolean;
530
+ /** The tier written (`null` for none), the model asked and its effort
531
+ * (`null` when the tier leaves it to the model). */
532
+ tier?: string | null;
533
+ model?: string;
534
+ effort?: string | null;
525
535
  }
526
536
  /**
527
537
  * A warning about the run that did not stop it — a movement pinned to a
@@ -875,9 +875,7 @@ function traceEntry(value) {
875
875
  case 'read':
876
876
  return readTraceEntry(entry);
877
877
  case 'ai':
878
- if (typeof entry.hasValue !== 'boolean')
879
- throw new rust_wire_1.RustShimError('an ai trace entry says whether the model answered');
880
- return { kind: 'ai', prompt: (0, rust_wire_1.string)(entry.prompt, 'an ai prompt'), hasValue: entry.hasValue };
878
+ return aiTraceEntry(entry);
881
879
  case 'extraction':
882
880
  return extractionTraceEntry(entry);
883
881
  case 'plugin':
@@ -937,6 +935,22 @@ function readTraceEntry(entry) {
937
935
  throw new rust_wire_1.RustShimError(`a read trace entry does not read: ${parsed.error.message}`);
938
936
  return { kind: 'read', ...parsed.data };
939
937
  }
938
+ /** An `AI()` call's trace entry as crates/movement-engine/src/trace.rs writes
939
+ * it; an artifact built before it named its tier, model and effort names none. */
940
+ const aiTraceEntrySchema = zod_1.z.strictObject({
941
+ kind: zod_1.z.literal('ai'),
942
+ prompt: zod_1.z.string(),
943
+ hasValue: zod_1.z.boolean(),
944
+ tier: zod_1.z.string().nullable().optional(),
945
+ model: zod_1.z.string().optional(),
946
+ effort: zod_1.z.string().nullable().optional(),
947
+ });
948
+ function aiTraceEntry(entry) {
949
+ const parsed = aiTraceEntrySchema.safeParse(entry);
950
+ if (!parsed.success)
951
+ throw new rust_wire_1.RustShimError(`an ai trace entry does not read: ${parsed.error.message}`);
952
+ return parsed.data;
953
+ }
940
954
  /** An extraction's trace entry as crates/movement-engine/src/extract/run.rs
941
955
  * (and extract/call.rs, `form: 'call'`) writes it, held to expression.ts's
942
956
  * type member by member. */
@@ -949,7 +963,9 @@ const extractionTraceEntrySchema = zod_1.z.strictObject({
949
963
  inputsTruncated: zod_1.z.number().optional(),
950
964
  files: zod_1.z.array(tracedFile).optional(),
951
965
  filesTruncated: zod_1.z.number().optional(),
966
+ tier: zod_1.z.string().nullable().optional(),
952
967
  model: zod_1.z.string().optional(),
968
+ effort: zod_1.z.string().nullable().optional(),
953
969
  durationMs: zod_1.z.number().optional(),
954
970
  effortSteppedDown: zod_1.z.object({ from: zod_1.z.string(), to: zod_1.z.string() }).optional(),
955
971
  continued: zod_1.z.literal(true).optional(),
@@ -87,3 +87,46 @@ export interface DeliveryContractCase {
87
87
  run(backend: DeliveryContractBackend): Promise<void>;
88
88
  }
89
89
  export declare const deliveryContractCases: DeliveryContractCase[];
90
+ export interface RerunContractBackend {
91
+ startRun(input: {
92
+ id: string;
93
+ file: string;
94
+ movement: string;
95
+ startedAt: string;
96
+ input: string;
97
+ }): Promise<void>;
98
+ runGet(input: {
99
+ runId: string;
100
+ }): Promise<RunRow | null>;
101
+ runSettle(input: {
102
+ runId: string;
103
+ status: string;
104
+ outcome: unknown;
105
+ at: string;
106
+ }): Promise<void>;
107
+ runRerun(input: {
108
+ runId: string;
109
+ input: string;
110
+ at: string;
111
+ fence: string;
112
+ }): Promise<number | null>;
113
+ markFailed(input: {
114
+ runId: string;
115
+ message: string;
116
+ }): Promise<void>;
117
+ claimLease(input: {
118
+ runId: string;
119
+ ttlMs: number;
120
+ }): Promise<{
121
+ token: string;
122
+ } | null>;
123
+ releaseLease(input: {
124
+ runId: string;
125
+ token: string;
126
+ }): Promise<void>;
127
+ }
128
+ export interface RerunContractCase {
129
+ name: string;
130
+ run(backend: RerunContractBackend): Promise<void>;
131
+ }
132
+ export declare const rerunContractCases: RerunContractCase[];
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.deliveryContractCases = exports.cancelContractCases = exports.callbackContractCases = exports.runHostContractCases = void 0;
16
+ exports.rerunContractCases = exports.deliveryContractCases = exports.cancelContractCases = exports.callbackContractCases = exports.runHostContractCases = void 0;
17
17
  const strict_1 = __importDefault(require("node:assert/strict"));
18
18
  const node_crypto_1 = require("node:crypto");
19
19
  const errors_1 = require("../movement_engine/errors");
@@ -1118,3 +1118,86 @@ exports.deliveryContractCases = [
1118
1118
  },
1119
1119
  },
1120
1120
  ];
1121
+ const WROTE = { adapter: 'crm', recordType: 'Company', recordId: 'c-1', action: 'create', committed: true, values: {} };
1122
+ /** A run started then settled `status` with `outcome`, a millisecond apart. */
1123
+ async function settledRun(backend, status, outcome) {
1124
+ const id = (0, node_crypto_1.randomUUID)();
1125
+ await backend.startRun({ id, file: 'f', movement: 'm', startedAt: PAST(10), input: '{"attempt":1}' });
1126
+ await backend.runSettle({ runId: id, status, outcome, at: PAST(9) });
1127
+ return id;
1128
+ }
1129
+ async function leased(backend, runId) {
1130
+ const lease = await backend.claimLease({ runId, ttlMs: 60_000 });
1131
+ strict_1.default.ok(lease, 'the run is not held');
1132
+ return lease.token;
1133
+ }
1134
+ exports.rerunContractCases = [
1135
+ {
1136
+ name: "reruns: a failed run's rerun is its next attempt, the failed one kept beside it",
1137
+ async run(backend) {
1138
+ const runId = await settledRun(backend, 'failed', { error: 'boom', writes: 1, writeRecords: [WROTE] });
1139
+ const before = await backend.runGet({ runId });
1140
+ strict_1.default.equal(before?.attempt ?? 1, 1);
1141
+ strict_1.default.deepEqual(before?.attempts ?? [], []);
1142
+ strict_1.default.deepEqual(JSON.parse(before?.outcome ?? 'null'), { error: 'boom', writes: 1, writeRecords: [WROTE] }, 'a failed outcome keeps its writes');
1143
+ const fence = await leased(backend, runId);
1144
+ const at = PAST(1);
1145
+ strict_1.default.equal(await backend.runRerun({ runId, input: '{"attempt":2}', at, fence }), 2);
1146
+ const row = await backend.runGet({ runId });
1147
+ strict_1.default.ok(row);
1148
+ strict_1.default.deepEqual([row.status, row.attempt, row.input, row.startedAt, row.finishedAt ?? null], ['running', 2, '{"attempt":2}', at, null]);
1149
+ // The new attempt has written nothing yet (a store may answer `{ writes: 0 }` for none).
1150
+ const fresh = JSON.parse(row.outcome ?? '{}');
1151
+ strict_1.default.deepEqual([fresh.error, fresh.writes ?? 0, fresh.writeRecords], [undefined, 0, undefined]);
1152
+ strict_1.default.equal(row.attempts?.length, 1);
1153
+ const [first] = row.attempts;
1154
+ strict_1.default.deepEqual([first.attempt, first.status, first.startedAt, first.finishedAt], [1, 'failed', before.startedAt, before.finishedAt]);
1155
+ strict_1.default.deepEqual(first.outcome, { error: 'boom', writes: 1, writeRecords: [WROTE] });
1156
+ await backend.runSettle({ runId, status: 'failed', outcome: { error: 'boom again', writes: 0, writeRecords: [] }, at: PAST(0.5) });
1157
+ strict_1.default.equal(await backend.runRerun({ runId, input: '{"attempt":3}', at: PAST(0.2), fence }), 3);
1158
+ const third = await backend.runGet({ runId });
1159
+ strict_1.default.deepEqual(third?.attempts?.map((a) => [a.attempt, a.status]), [[1, 'failed'], [2, 'failed']]);
1160
+ strict_1.default.equal(third?.attempt, 3);
1161
+ await backend.releaseLease({ runId, token: fence });
1162
+ },
1163
+ },
1164
+ {
1165
+ name: 'reruns: a run whose latest attempt did not fail is not rerun, and nothing is written',
1166
+ async run(backend) {
1167
+ const completed = await settledRun(backend, 'completed', { writes: 0, writeRecords: [] });
1168
+ const running = (0, node_crypto_1.randomUUID)();
1169
+ await backend.startRun({ id: running, file: 'f', movement: 'm', startedAt: PAST(1), input: '{}' });
1170
+ const parked = await settledRun(backend, 'parked', { writes: 0 });
1171
+ for (const runId of [completed, running, parked]) {
1172
+ const before = await backend.runGet({ runId });
1173
+ const fence = await leased(backend, runId);
1174
+ strict_1.default.equal(await backend.runRerun({ runId, input: '{"attempt":2}', at: PAST(0), fence }), null, before?.status);
1175
+ const after = await backend.runGet({ runId });
1176
+ strict_1.default.deepEqual([after?.status, after?.attempt ?? 1, after?.input, after?.attempts ?? []], [before?.status, 1, before?.input, []]);
1177
+ await backend.releaseLease({ runId, token: fence });
1178
+ }
1179
+ },
1180
+ },
1181
+ {
1182
+ name: 'reruns: a rerun is fenced by the run lease',
1183
+ async run(backend) {
1184
+ const runId = await settledRun(backend, 'failed', { error: 'boom' });
1185
+ await strict_1.default.rejects(backend.runRerun({ runId, input: '{}', at: PAST(0), fence: (0, node_crypto_1.randomUUID)() }), errors_1.RunLeaseLost);
1186
+ const fence = await leased(backend, runId);
1187
+ await strict_1.default.rejects(backend.runRerun({ runId, input: '{}', at: PAST(0), fence: (0, node_crypto_1.randomUUID)() }), errors_1.RunLeaseLost, 'another token');
1188
+ const row = await backend.runGet({ runId });
1189
+ strict_1.default.deepEqual([row?.status, row?.attempt ?? 1], ['failed', 1]);
1190
+ await backend.releaseLease({ runId, token: fence });
1191
+ },
1192
+ },
1193
+ {
1194
+ name: "reruns: a run failed by markFailed keeps the writes it settled with",
1195
+ async run(backend) {
1196
+ const runId = await settledRun(backend, 'parked', { writes: 1, writeRecords: [WROTE] });
1197
+ await backend.markFailed({ runId, message: 'cancelled by the operator' });
1198
+ const row = await backend.runGet({ runId });
1199
+ strict_1.default.equal(row?.status, 'failed');
1200
+ strict_1.default.deepEqual(JSON.parse(row?.outcome ?? 'null'), { error: 'cancelled by the operator', writes: 1, writeRecords: [WROTE] });
1201
+ },
1202
+ },
1203
+ ];
@@ -50,6 +50,21 @@ export interface RunRow {
50
50
  input: string;
51
51
  outcome: string | null;
52
52
  deliveryId: string | null;
53
+ /** When it last settled completed or failed; a store that keeps none answers none. */
54
+ finishedAt?: string | null;
55
+ /** The latest attempt's number; a store that keeps no attempts answers none (1). */
56
+ attempt?: number;
57
+ /** The run's earlier attempts, oldest first. */
58
+ attempts?: RunAttempt[];
59
+ }
60
+ /** One earlier attempt of a run, as `runs.rerun` kept it. */
61
+ export interface RunAttempt {
62
+ attempt: number;
63
+ status: string;
64
+ startedAt: string;
65
+ finishedAt: string | null;
66
+ /** The JSON object it settled with: `{ error, writes?, writeRecords? }` for a failed one. */
67
+ outcome: unknown;
53
68
  }
54
69
  export declare class RpcStoreBackend {
55
70
  readonly store: RunHostStore;
@@ -77,6 +92,21 @@ export declare class RpcStoreBackend {
77
92
  runGet(input: {
78
93
  runId: string;
79
94
  }): Promise<RunRow | null>;
95
+ /** Where the run stands (`runs.settle`): an ending revokes its callbacks. */
96
+ runSettle(input: {
97
+ runId: string;
98
+ status: string;
99
+ outcome: unknown;
100
+ at: string;
101
+ }): Promise<void>;
102
+ /** The run's next attempt, under its lease (`runs.rerun`): its number, or
103
+ * null when the run's latest attempt did not fail. */
104
+ runRerun(input: {
105
+ runId: string;
106
+ input: string;
107
+ at: string;
108
+ fence: string;
109
+ }): Promise<number | null>;
80
110
  /** The door's one write: the receipt, the cursor (absent: left as it is)
81
111
  * and the work rows; `kept: false`, and nothing written, for a duplicate. */
82
112
  keepDelivery(input: {
@@ -73,6 +73,11 @@ const Run = zod_1.z.object({
73
73
  input: zod_1.z.string(),
74
74
  outcome: zod_1.z.string().nullable(),
75
75
  deliveryId: zod_1.z.string().nullable(),
76
+ finishedAt: zod_1.z.string().nullable().optional(),
77
+ attempt: zod_1.z.number().optional(),
78
+ attempts: zod_1.z
79
+ .array(zod_1.z.object({ attempt: zod_1.z.number(), status: zod_1.z.string(), startedAt: zod_1.z.string(), finishedAt: zod_1.z.string().nullable(), outcome: zod_1.z.unknown() }))
80
+ .optional(),
76
81
  });
77
82
  /** The work claim the server reads: no more than it needs, whatever the caller spreads in. */
78
83
  function claimOf(work) {
@@ -119,6 +124,16 @@ class RpcStoreBackend {
119
124
  runGet(input) {
120
125
  return this.call('runs.get', input, Run.nullable());
121
126
  }
127
+ /** Where the run stands (`runs.settle`): an ending revokes its callbacks. */
128
+ async runSettle(input) {
129
+ await this.call('runs.settle', input, Nothing);
130
+ }
131
+ /** The run's next attempt, under its lease (`runs.rerun`): its number, or
132
+ * null when the run's latest attempt did not fail. */
133
+ async runRerun(input) {
134
+ const answer = await this.call('runs.rerun', input, zod_1.z.object({ attempt: zod_1.z.number() }).nullable());
135
+ return answer?.attempt ?? null;
136
+ }
122
137
  /** The door's one write: the receipt, the cursor (absent: left as it is)
123
138
  * and the work rows; `kept: false`, and nothing written, for a duplicate. */
124
139
  keepDelivery(input) {
@@ -388,6 +388,8 @@ function instanceSchemaFromDescriptors(input) {
388
388
  const writeOnlyProperties = [];
389
389
  /** Display names carried by more than one of the source's fields. */
390
390
  const ambiguousProperties = [];
391
+ /** Fields a read must pin in its WHERE (the descriptor's `pinned`). */
392
+ const pinnedProperties = [];
391
393
  const requiredFields = [];
392
394
  const fieldDocs = {};
393
395
  /** Every described field's words, readable or write-only: the position's. */
@@ -423,6 +425,8 @@ function instanceSchemaFromDescriptors(input) {
423
425
  const description = describedBy(field);
424
426
  if (description !== undefined)
425
427
  positionFieldDocs[fieldName] = description;
428
+ if (field.pinned === true)
429
+ pinnedProperties.push(fieldName);
426
430
  if (field.readable === false) {
427
431
  // A WRITE-ONLY field (WhatsApp's send-side `File`): it stays on the
428
432
  // write shape below, but is DELIBERATELY absent from the readable
@@ -606,6 +610,7 @@ function instanceSchemaFromDescriptors(input) {
606
610
  ...(droppedField ? { openProperties: true } : {}),
607
611
  ...(writeOnlyProperties.length > 0 ? { writeOnlyProperties } : {}),
608
612
  ...(ambiguousProperties.length > 0 ? { ambiguousProperties } : {}),
613
+ ...(pinnedProperties.length > 0 ? { pinnedProperties } : {}),
609
614
  // The system removes a record of this type (its `deleteRecord`) — the
610
615
  // promise `delete x` is checked against.
611
616
  ...(descriptor.deletable === true ? { deletable: true } : {}),
@@ -1,4 +1,5 @@
1
1
  import type { DiscriminableEvent } from '../adapter';
2
+ import type { FileListener } from '../movement/file_listeners';
2
3
  export declare function eventConfigList(events: unknown): string[];
3
4
  /**
4
5
  * Whether a trigger's `channels` listen filter admits an event in `channelName`
@@ -12,7 +13,7 @@ export declare function eventConfigList(events: unknown): string[];
12
13
  */
13
14
  export declare function channelScopeMatches(config: unknown, channelName: string | null): boolean;
14
15
  /**
15
- * Does this event clear a trigger's `listen` scope? Two gates, both from the
16
+ * Does this event clear a trigger's `listen` scope? Gates, all from the
16
17
  * trigger's `config`:
17
18
  * • `events: [...]` — the chosen change types (`record.created`, …). The
18
19
  * authored selection that the source registration already narrowed to;
@@ -21,5 +22,43 @@ export declare function channelScopeMatches(config: unknown, channelName: string
21
22
  * a delivery for base B reaches every trigger on B's credential; this keeps
22
23
  * a table-T listen from firing on table-U changes (no cross-leak, no wasted
23
24
  * run). The event names its table in `recordType`.
25
+ * • `field: "Stage"` — only a change that touched that field (the event's
26
+ * `changedFields`). With `becomes: <value>`, only a change that made the
27
+ * field that value: its new value is it, and its previous value was not
28
+ * (`FieldChangePayload`). An event that names no changed fields never
29
+ * clears a `field` gate: we don't fire on a change we can't confirm.
24
30
  */
25
31
  export declare function eventMatchesTriggerScope(event: DiscriminableEvent, config: unknown): boolean;
32
+ /**
33
+ * Whether a delivery for `delivered` reaches a listen whose construction names
34
+ * `listened` (the credential each names, by its imported name): the
35
+ * platform's per-trigger credential narrowing, which lf keeps too
36
+ * (crates/lf/src/routing.rs, `Listen::hears`). A listen that names a
37
+ * credential hears only that credential's deliveries; a listen that names
38
+ * none hears every delivery, and a delivery that names none (addressed to the
39
+ * module's install, which serves every connection) reaches every listen.
40
+ */
41
+ export declare function listenHearsCredential(listened: string | undefined, delivered: string | undefined): boolean;
42
+ /**
43
+ * Whether an event from `adapterType`, delivered for the connection named
44
+ * `credentialName` (absent: the module's install), reaches `listener`: the
45
+ * listen is on that adapter, hears that credential, and its scope admits the
46
+ * event. The whole routing rule an embedded host applies to each listen of a
47
+ * tenant's saved programs.
48
+ */
49
+ export declare function listenerHearsDelivery(listener: Pick<FileListener, 'adapter' | 'credentialName' | 'config'>, delivery: {
50
+ adapterType: string;
51
+ credentialName?: string;
52
+ event: DiscriminableEvent;
53
+ }): boolean;
54
+ /**
55
+ * What an event payload carries for a `becomes` gate to read: the changed
56
+ * fields' new values (`fields`) and their previous ones (`previous`), keyed by
57
+ * the name a listen's `field` uses. An adapter that declares a `becomes` listen
58
+ * key shapes its event payload so. A field missing from `previous` (a created
59
+ * record, or a source that did not send previous values) had no value before.
60
+ */
61
+ export interface FieldChangePayload {
62
+ fields: Record<string, unknown>;
63
+ previous?: Record<string, unknown>;
64
+ }
@@ -18,6 +18,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.eventConfigList = eventConfigList;
19
19
  exports.channelScopeMatches = channelScopeMatches;
20
20
  exports.eventMatchesTriggerScope = eventMatchesTriggerScope;
21
+ exports.listenHearsCredential = listenHearsCredential;
22
+ exports.listenerHearsDelivery = listenerHearsDelivery;
21
23
  function eventConfigList(events) {
22
24
  if (Array.isArray(events))
23
25
  return events.filter((e) => typeof e === 'string');
@@ -42,7 +44,7 @@ function channelScopeMatches(config, channelName) {
42
44
  return channelName != null && channels.includes(channelName);
43
45
  }
44
46
  /**
45
- * Does this event clear a trigger's `listen` scope? Two gates, both from the
47
+ * Does this event clear a trigger's `listen` scope? Gates, all from the
46
48
  * trigger's `config`:
47
49
  * • `events: [...]` — the chosen change types (`record.created`, …). The
48
50
  * authored selection that the source registration already narrowed to;
@@ -51,6 +53,11 @@ function channelScopeMatches(config, channelName) {
51
53
  * a delivery for base B reaches every trigger on B's credential; this keeps
52
54
  * a table-T listen from firing on table-U changes (no cross-leak, no wasted
53
55
  * run). The event names its table in `recordType`.
56
+ * • `field: "Stage"` — only a change that touched that field (the event's
57
+ * `changedFields`). With `becomes: <value>`, only a change that made the
58
+ * field that value: its new value is it, and its previous value was not
59
+ * (`FieldChangePayload`). An event that names no changed fields never
60
+ * clears a `field` gate: we don't fire on a change we can't confirm.
54
61
  */
55
62
  function eventMatchesTriggerScope(event, config) {
56
63
  const c = config;
@@ -63,5 +70,50 @@ function eventMatchesTriggerScope(event, config) {
63
70
  if (event.recordType !== undefined && event.recordType !== c.table)
64
71
  return false;
65
72
  }
73
+ if (typeof c?.field === 'string' && c.field.length > 0) {
74
+ if (!(event.changedFields ?? []).includes(c.field))
75
+ return false;
76
+ if (c.becomes !== undefined && !becameValue(event.payload, c.field, c.becomes))
77
+ return false;
78
+ }
66
79
  return true;
67
80
  }
81
+ /**
82
+ * Whether a delivery for `delivered` reaches a listen whose construction names
83
+ * `listened` (the credential each names, by its imported name): the
84
+ * platform's per-trigger credential narrowing, which lf keeps too
85
+ * (crates/lf/src/routing.rs, `Listen::hears`). A listen that names a
86
+ * credential hears only that credential's deliveries; a listen that names
87
+ * none hears every delivery, and a delivery that names none (addressed to the
88
+ * module's install, which serves every connection) reaches every listen.
89
+ */
90
+ function listenHearsCredential(listened, delivered) {
91
+ return listened === undefined || delivered === undefined || listened === delivered;
92
+ }
93
+ /**
94
+ * Whether an event from `adapterType`, delivered for the connection named
95
+ * `credentialName` (absent: the module's install), reaches `listener`: the
96
+ * listen is on that adapter, hears that credential, and its scope admits the
97
+ * event. The whole routing rule an embedded host applies to each listen of a
98
+ * tenant's saved programs.
99
+ */
100
+ function listenerHearsDelivery(listener, delivery) {
101
+ return (listener.adapter === delivery.adapterType &&
102
+ listenHearsCredential(listener.credentialName, delivery.credentialName) &&
103
+ eventMatchesTriggerScope(delivery.event, listener.config));
104
+ }
105
+ function becameValue(payload, field, value) {
106
+ const cells = (key) => {
107
+ const held = typeof payload === 'object' && payload !== null ? Reflect.get(payload, key) : undefined;
108
+ return typeof held === 'object' && held !== null ? held : {};
109
+ };
110
+ return sameValue(cells('fields')[field], value) && !sameValue(cells('previous')[field], value);
111
+ }
112
+ /** Equal as data: a list or an object by its contents. */
113
+ function sameValue(a, b) {
114
+ if (a === b)
115
+ return true;
116
+ if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null)
117
+ return false;
118
+ return JSON.stringify(a) === JSON.stringify(b);
119
+ }
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.12.9",
4
+ "version": "0.12.11",
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 `lf` 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.12.9",
21
- "@listen-fire/module-runtime": "^0.12.7",
22
- "@listen-fire/movement-lang": "^0.12.9"
20
+ "@listen-fire/engine-contracts": "^0.12.11",
21
+ "@listen-fire/module-runtime": "^0.12.8",
22
+ "@listen-fire/movement-lang": "^0.12.11"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/jest": "29.5.14",