@listen-fire/engine 0.12.8 → 0.12.10
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/limiter/contract.js +3 -1
- package/dist/services/movement_engine/run_types.d.ts +12 -2
- package/dist/services/movement_engine/rust_host.js +19 -3
- package/dist/services/translation_graph/movement/schema_projection.js +5 -0
- package/dist/services/translation_graph/triggers/listen_config.d.ts +40 -1
- package/dist/services/translation_graph/triggers/listen_config.js +53 -1
- package/package.json +4 -4
|
@@ -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
|
-
|
|
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
|
-
/**
|
|
317
|
-
*
|
|
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
|
-
|
|
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(),
|
|
@@ -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?
|
|
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?
|
|
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.
|
|
4
|
+
"version": "0.12.10",
|
|
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/
|
|
21
|
-
"@listen-fire/engine-contracts": "^0.12.
|
|
22
|
-
"@listen-fire/
|
|
20
|
+
"@listen-fire/module-runtime": "^0.12.8",
|
|
21
|
+
"@listen-fire/engine-contracts": "^0.12.10",
|
|
22
|
+
"@listen-fire/movement-lang": "^0.12.10"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/jest": "29.5.14",
|