@listen-fire/engine-contracts 0.15.2 → 0.16.0

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/adapter.d.ts CHANGED
@@ -14,74 +14,6 @@ export type { ConfigBlock } from './config_blocks';
14
14
  export { fileDescriptorOf, fileHandle, fileValue, fileValueOf, filesAtType, isFileValue, ownedFileSource } from './file_ref';
15
15
  export type { EarlierFileSource, FileRef, FileSource, FileValue } from './file_ref';
16
16
  export type { ExternalRecordRef, Fact, FieldEvidence, Resource, ResourceProvenance } from './records';
17
- /**
18
- * Minimal user descriptor returned by Listen-Fire's `resolveActingUser`
19
- * (acting_user/resolve.ts) and consumed by the engine's meta resolver to
20
- * populate `@user_email`,
21
- * `@user_name`, and `@user_id`. Kept shape-loose (name optional) so
22
- * adapters that can only surface an email don't have to fabricate a
23
- * display name.
24
- *
25
- */
26
- export interface ActingUser {
27
- id: string;
28
- email: string;
29
- name?: string | null;
30
- }
31
- /**
32
- * Raw event-side actor identity returned by `Adapter.extractActor`. Distinct
33
- * from `ActingUser`: an `ActorIdentity` is the external originator of the
34
- * event (the `From:` address on an email, the Slack user that posted, the
35
- * Attio actor that wrote a record) regardless of whether they are a
36
- * registered Listen-Fire team member. Powers `@actor_email` / `@actor_name` /
37
- * `@actor_id` so authors can compare "the team member responsible for this
38
- * dispatch" (`@user_*`) with "who actually originated the event" (`@actor_*`).
39
- *
40
- * Parsed from the event payload — no DB lookups — because actor identity
41
- * is a parse, not an auth decision. The method is async only so a remote
42
- * adapter can answer it over the wire; local impls are still pure parses.
43
- *
44
- */
45
- export interface ActorIdentity {
46
- /** Primary key in the source system (email address, phone number,
47
- * Slack user id, Attio actor id, etc.). */
48
- identifier: string;
49
- /** How this identity resolves to a Listen-Fire team user — the only thing the
50
- * resolution logic cares about, independent of which adapter produced it:
51
- * • `'email'` — resolvable to a team user by email (the address is on
52
- * `identifier` or `email`).
53
- * • `'phone'` — resolvable to a team user by phone number.
54
- * • `'opaque'` — neither; a raw external id with no resolved email/phone,
55
- * so it maps to no Listen-Fire user (e.g. a bare Slack/Attio id from the
56
- * pure-parse `extractActor`). Resolvers skip it rather than guessing. */
57
- scheme: 'email' | 'phone' | 'opaque';
58
- /** Which adapter sourced this identity — provenance only; the resolution
59
- * logic never branches on it (it branches on `scheme`). */
60
- adapterType?: string;
61
- /** Email address when the source carries one (every email event; Slack
62
- * messages don't have this without an API call). */
63
- email?: string;
64
- /** Display name (the friendly part of `"Ada" <h@x>`; Slack display
65
- * name; etc.). */
66
- name?: string;
67
- /** Fallback display label when `name` isn't available. */
68
- label?: string;
69
- }
70
- /**
71
- * An ordered actor candidate parsed from an inbound event by the adapter's
72
- * `getActorCandidates`. Distinct from `ActorIdentity` (the raw event
73
- * originator surfaced via `@actor_*`): a candidate is a *resolution input*
74
- * Listen-Fire's `resolveActingUser` maps to a team user. The `source` tag drives
75
- * the resolution order — `originator` candidates (who sent it) are matched
76
- * against non-service users first; `relay` candidates (the forwarding /
77
- * service inbox that delivered it) are matched against service users only.
78
- *
79
- */
80
- export interface ActorCandidate {
81
- identity: ActorIdentity;
82
- /** who-sent-it (`originator`) vs forwarding/service-inbox (`relay`). */
83
- source: 'originator' | 'relay';
84
- }
85
17
  /**
86
18
  * The protocol method names a write goes through. Used as the capability
87
19
  * basis for "is this adapter a valid TG target" — a manifest whose `methods`
@@ -248,21 +180,24 @@ export interface AdapterManifest {
248
180
  */
249
181
  triggerExpectation?: string;
250
182
  /**
251
- * Ownership gating for inbound events (message-write-unification §6.4b):
252
- * when true, the dispatcher processes an inbound event ONLY if its actor
253
- * resolves to a REGISTERED team user (the adapter's `getActorCandidates`
254
- * chain matched by `resolveActingUser`, WITHOUT trigger context — creator
255
- * override/fallback never pass the gate). The bot is never a registered
256
- * user, so self-echo drops for free; an unregistered person is dropped by
257
- * the same rule. Dropped events are recorded (receipt marked suppressed,
258
- * replayable), never silent. Set by adapters whose inbound channel is
259
- * globally addressable (Slack: anyone in the workspace can @-mention the
260
- * bot); adapters whose inbound is already identity-gated upstream omit it
261
- * (WhatsApp's sender→team resolution; Telegram's /start handshake binding
262
- * ON THE BUILT-IN SHARED BOT — a team running its own bot has no such
263
- * gate, so a BYO-bot team's inbound is not actually identity-gated here).
264
- */
265
- inboundRequiresRegisteredActor?: boolean;
183
+ * The release before which a host may have let only registered senders set
184
+ * a listen on this module off (Slack: `'0.16.0'`, when the hosted
185
+ * platform's gate on registered team members retired). From it, only a
186
+ * listen's filter decides who sets it off. An upgrade from an older key
187
+ * tells each listen whose filter does not limit it (`MOV_LISTEN_NOW_OPEN`).
188
+ * Omitted: no host ever limited this module's listens.
189
+ */
190
+ listensLimitedBefore?: string;
191
+ /**
192
+ * Connection settings this module no longer reads. A host refuses a
193
+ * connection that still holds one, with `instead` in the message: a
194
+ * setting is kept with the connection, outside any movement, so no
195
+ * upgrade can rewrite it.
196
+ */
197
+ retiredSettings?: Array<{
198
+ name: string;
199
+ instead: string;
200
+ }>;
266
201
  /** True when this adapter's schema comes from LIVE introspection of the
267
202
  * connected workspace (attio, airtable, sheets, affinity) — a
268
203
  * describeInstance costs upstream API calls, so callers should scope with
@@ -770,55 +705,6 @@ export interface Adapter {
770
705
  getDedupRules?(input: {
771
706
  typeRef: string;
772
707
  }): Promise<DedupRules | null>;
773
- /**
774
- * Parse ordered actor candidates from an inbound event — a pure parse of
775
- * who-sent-it / who-relayed-it, with NO Listen-Fire DB access (external-system
776
- * API enrichment IS allowed: Slack `users.info`, Attio
777
- * `/v2/workspace_members/{id}`, etc., to surface the actor's email).
778
- *
779
- * This is the adapter half of the acting-user split (the extensible
780
- * adapter protocol, 2026-05-29). The adapter no longer reaches into
781
- * Listen-Fire's user tables — it only describes the candidates; Listen-Fire's
782
- * `resolveActingUser` (acting_user/resolve.ts) runs the identical
783
- * resolution chain (creator-override → originator/non-service →
784
- * relay/service → creator-fallback → null) by mapping these candidates
785
- * to a team user. Splitting parse from resolution lets the parse cross a
786
- * remote-adapter boundary that the DB chain never could.
787
- *
788
- * Candidate ordering and `source` tags reproduce the prior per-adapter
789
- * chains exactly:
790
- * - Email: sender (`From:` / `sender`) as `originator`; each parsed
791
- * forwarding-header recipient as `relay`.
792
- * - Slack / Attio: the runtime-resolved actor email as a single
793
- * `originator` candidate (empty array when no email resolves).
794
- *
795
- * The terminal recipient on the deployment's own inbound address is ROUTING ONLY and is never a
796
- * candidate — auth comes from who SENT it or which inbox RELAYED it.
797
- *
798
- * Optional — adapters with no acting-user concept omit it; the resolver
799
- * then yields null (no `@user_*`). `extractActor` (`@actor_*`) is
800
- * independent of this method.
801
- *
802
- */
803
- getActorCandidates?(input: {
804
- event: TriggerEvent;
805
- }): Promise<ActorCandidate[]>;
806
- /**
807
- * Extract the raw actor identity from an inbound event. A pure parse,
808
- * no DB lookups — actor identity is "who originated this event
809
- * in the source system" regardless of whether they map to a Listen-Fire
810
- * user. Powers `@actor_email` / `@actor_name` / `@actor_id` so authors
811
- * can attribute events to their raw originator independently of the
812
- * authenticated team member.
813
- *
814
- * Returns `null` when the event has no actor-shaped originator (e.g.
815
- * a snapshot replay with no per-record provenance). Adapters that
816
- * don't implement get `@actor_*` = null at dispatch time, gracefully.
817
- *
818
- */
819
- extractActor?(input: {
820
- event: TriggerEvent;
821
- }): Promise<ActorIdentity | null>;
822
708
  didWeAuthor?(input: {
823
709
  event: TriggerEvent;
824
710
  }): Promise<boolean | null>;
@@ -1,4 +1,3 @@
1
- import type { ActorIdentity } from './adapter';
2
1
  /** A record a run waits on: the id its write answered, the data it
3
2
  * carried (Slack keys a thread by the channel in it, not by its id), and its
4
3
  * record type, as the module names it, wherever the host knows it (2.6). A
@@ -62,11 +61,6 @@ export type Arrival = {
62
61
  * it, however late a poll finds it (2.6), and the run it fires
63
62
  * stamps its writes with it (2.7). */
64
63
  occurredAt?: string;
65
- /** Who acted, where the provider says: the member who posted, the
66
- * sender of the mail, the owner of the meeting (2.7). The run's
67
- * `@actor_*` reads it, and a host resolves the acting user from it;
68
- * set at the door, so nothing after it needs the raw event. */
69
- actor?: ActorIdentity;
70
64
  } | {
71
65
  edge: string;
72
66
  key: string;
package/dist/catalog.d.ts CHANGED
@@ -32,6 +32,13 @@ export type ExpressionType = {
32
32
  } | {
33
33
  kind: 'record';
34
34
  fields: Record<string, ExpressionType>;
35
+ } | {
36
+ kind: 'branded';
37
+ of: ExpressionType;
38
+ brands: string[];
39
+ } | {
40
+ kind: 'union';
41
+ of: ExpressionType[];
35
42
  };
36
43
  export declare const genericEdgeSchema: z.ZodObject<{
37
44
  target: z.ZodType<ExpressionType, unknown, z.core.$ZodTypeInternals<ExpressionType, unknown>>;
@@ -480,6 +487,7 @@ export declare const schemaFieldDescriptorSchema: z.ZodObject<{
480
487
  typeId: z.ZodString;
481
488
  }, z.core.$strip>>;
482
489
  mayBeAbsent: z.ZodOptional<z.ZodBoolean>;
490
+ brands: z.ZodOptional<z.ZodArray<z.ZodString>>;
483
491
  changedIn: z.ZodOptional<z.ZodObject<{
484
492
  release: z.ZodString;
485
493
  note: z.ZodString;
@@ -668,6 +676,7 @@ export declare const schemaReferenceDescriptorSchema: z.ZodPreprocess<z.ZodObjec
668
676
  typeId: z.ZodString;
669
677
  }, z.core.$strip>>;
670
678
  mayBeAbsent: z.ZodOptional<z.ZodBoolean>;
679
+ brands: z.ZodOptional<z.ZodArray<z.ZodString>>;
671
680
  changedIn: z.ZodOptional<z.ZodObject<{
672
681
  release: z.ZodString;
673
682
  note: z.ZodString;
@@ -843,6 +852,7 @@ export declare const schemaTypeDescriptorSchema: z.ZodObject<{
843
852
  typeId: z.ZodString;
844
853
  }, z.core.$strip>>;
845
854
  mayBeAbsent: z.ZodOptional<z.ZodBoolean>;
855
+ brands: z.ZodOptional<z.ZodArray<z.ZodString>>;
846
856
  changedIn: z.ZodOptional<z.ZodObject<{
847
857
  release: z.ZodString;
848
858
  note: z.ZodString;
@@ -1005,6 +1015,7 @@ export declare const schemaTypeDescriptorSchema: z.ZodObject<{
1005
1015
  typeId: z.ZodString;
1006
1016
  }, z.core.$strip>>;
1007
1017
  mayBeAbsent: z.ZodOptional<z.ZodBoolean>;
1018
+ brands: z.ZodOptional<z.ZodArray<z.ZodString>>;
1008
1019
  changedIn: z.ZodOptional<z.ZodObject<{
1009
1020
  release: z.ZodString;
1010
1021
  note: z.ZodString;
@@ -1236,6 +1247,7 @@ declare const schemaDescriptorSchema: z.ZodObject<{
1236
1247
  typeId: z.ZodString;
1237
1248
  }, z.core.$strip>>;
1238
1249
  mayBeAbsent: z.ZodOptional<z.ZodBoolean>;
1250
+ brands: z.ZodOptional<z.ZodArray<z.ZodString>>;
1239
1251
  changedIn: z.ZodOptional<z.ZodObject<{
1240
1252
  release: z.ZodString;
1241
1253
  note: z.ZodString;
@@ -1398,6 +1410,7 @@ declare const schemaDescriptorSchema: z.ZodObject<{
1398
1410
  typeId: z.ZodString;
1399
1411
  }, z.core.$strip>>;
1400
1412
  mayBeAbsent: z.ZodOptional<z.ZodBoolean>;
1413
+ brands: z.ZodOptional<z.ZodArray<z.ZodString>>;
1401
1414
  changedIn: z.ZodOptional<z.ZodObject<{
1402
1415
  release: z.ZodString;
1403
1416
  note: z.ZodString;
@@ -1690,6 +1703,7 @@ declare const transformOutputKindSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1690
1703
  optional: z.ZodOptional<z.ZodBoolean>;
1691
1704
  description: z.ZodOptional<z.ZodString>;
1692
1705
  }, z.core.$strip>>;
1706
+ optional: z.ZodOptional<z.ZodBoolean>;
1693
1707
  }, z.core.$strip>, z.ZodObject<{
1694
1708
  kind: z.ZodLiteral<"records">;
1695
1709
  fields: z.ZodRecord<z.ZodString, z.ZodObject<{
@@ -1740,6 +1754,7 @@ declare const transformSignatureSchema: z.ZodObject<{
1740
1754
  optional: z.ZodOptional<z.ZodBoolean>;
1741
1755
  description: z.ZodOptional<z.ZodString>;
1742
1756
  }, z.core.$strip>>;
1757
+ optional: z.ZodOptional<z.ZodBoolean>;
1743
1758
  }, z.core.$strip>, z.ZodObject<{
1744
1759
  kind: z.ZodLiteral<"records">;
1745
1760
  fields: z.ZodRecord<z.ZodString, z.ZodObject<{
package/dist/catalog.js CHANGED
@@ -76,6 +76,20 @@ exports.expressionTypeSchema = zod_1.z.lazy(() => zod_1.z.discriminatedUnion('ki
76
76
  kind: zod_1.z.literal('record'),
77
77
  fields: zod_1.z.record(zod_1.z.string(), exports.expressionTypeSchema),
78
78
  }),
79
+ /** `string & Brand<"claim:email/address">`: `of` narrowed by each brand. A
80
+ * plugin parameter declares one; only a string or a number takes a brand. */
81
+ zod_1.z.object({
82
+ kind: zod_1.z.literal('branded'),
83
+ of: exports.expressionTypeSchema.refine((of) => of.kind === 'string' || of.kind === 'number', {
84
+ error: 'branded.of: expected a string or a number',
85
+ }),
86
+ brands: zod_1.z.array(zod_1.z.string().min(1)).min(1),
87
+ }),
88
+ /** One of several types, as the catalog spells a union. */
89
+ zod_1.z.object({
90
+ kind: zod_1.z.literal('union'),
91
+ of: zod_1.z.array(exports.expressionTypeSchema).min(1),
92
+ }),
79
93
  ]));
80
94
  // ── GenericShape: declared in-memory contract for a TG side ─────────────────
81
95
  // Used by `kind: 'generic'` schemaRefs. The shape declares properties (typed
@@ -741,6 +755,10 @@ exports.schemaFieldDescriptorSchema = zod_1.z.object({
741
755
  /** A record may not hold the field at all (a change's row before, when
742
756
  * the row was created): a read of it may be absent. Absent ⇒ false. */
743
757
  mayBeAbsent: zod_1.z.boolean().optional(),
758
+ /** With `kind: 'string'` or `'number'`: the module vouches for the value
759
+ * under these names (`claim:email/address`). A brand narrows the type, as
760
+ * TypeScript's intersection does; a name is compared whole, never parsed. */
761
+ brands: zod_1.z.array(zod_1.z.string().min(1)).min(1).optional(),
744
762
  /** The release that changed what the field holds, and how, as a check for
745
763
  * an upgrade from before it warns where a program reads it (gmail's
746
764
  * `Labels`: label ids before 0.13, names since). `unchangedValues` are
@@ -756,6 +774,13 @@ exports.schemaFieldDescriptorSchema = zod_1.z.object({
756
774
  message: `'${field.displayName}': 'owned' names the scalar of a field of kind 'owned', and only of one`,
757
775
  });
758
776
  }
777
+ if (field.brands !== undefined && field.kind !== 'string' && field.kind !== 'number') {
778
+ ctx.addIssue({
779
+ code: zod_1.z.ZodIssueCode.custom,
780
+ path: ['brands'],
781
+ message: `'${field.displayName}': 'brands' narrow a string or a number, and this field is of kind '${field.kind}'`,
782
+ });
783
+ }
759
784
  if ((field.kind === 'record') !== (field.record !== undefined)) {
760
785
  ctx.addIssue({
761
786
  code: zod_1.z.ZodIssueCode.custom,
@@ -2089,6 +2114,10 @@ const transformOutputKindSchema = zod_1.z.discriminatedUnion('kind', [
2089
2114
  zod_1.z.object({
2090
2115
  kind: zod_1.z.literal('record'),
2091
2116
  fields: zod_1.z.record(zod_1.z.string(), transformOutputFieldSchema),
2117
+ /** `{ … } | null`: the plugin may answer no record at all (a lookup that
2118
+ * found nobody). Read downstream as `record | absent`, so a field is
2119
+ * read off it with `?.`. */
2120
+ optional: zod_1.z.boolean().optional(),
2092
2121
  }),
2093
2122
  zod_1.z.object({
2094
2123
  kind: zod_1.z.literal('records'),
@@ -29,7 +29,6 @@
29
29
  "parents": [{ "recordId": "C1", "recordType": "Channel", "fields": { "Name": "deals" } }, null],
30
30
  "about": { "recordType": "Message", "externalId": "C1:1700000000.000100" },
31
31
  "occurredAt": "2023-11-14T22:14:10+00:00",
32
- "actor": { "identifier": "U1", "scheme": "opaque", "label": "U1" },
33
32
  "takenApplied": true
34
33
  },
35
34
  "trigger": {
@@ -41,8 +40,7 @@
41
40
  "edge": "Replies",
42
41
  "landing": { "recordId": "C1:1700000050.000200", "recordType": "Message", "fields": { "text": "on it", "user": "U1" } },
43
42
  "parents": [{ "recordId": "C1", "recordType": "Channel", "fields": { "Name": "deals" } }, null],
44
- "about": { "recordType": "Message", "externalId": "C1:1700000000.000100" },
45
- "actor": { "identifier": "U1", "scheme": "opaque", "label": "U1" }
43
+ "about": { "recordType": "Message", "externalId": "C1:1700000000.000100" }
46
44
  },
47
45
  "occurredAt": "2023-11-14T22:14:10.000Z"
48
46
  }
@@ -212,6 +212,22 @@
212
212
  "description": "the total",
213
213
  "type": "extract_value"
214
214
  },
215
+ "Field": {
216
+ "expression": {
217
+ "args": [
218
+ {
219
+ "fieldOnly": true,
220
+ "propertyTypeId": "Owner",
221
+ "type": "edge_property"
222
+ }
223
+ ],
224
+ "fn": "coalesce",
225
+ "type": "function"
226
+ },
227
+ "field": "Level",
228
+ "optional": true,
229
+ "type": "field"
230
+ },
215
231
  "Function": {
216
232
  "args": [
217
233
  {