salt-agent-sdk 0.25.0 → 0.26.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/README.md CHANGED
@@ -522,6 +522,15 @@ Asking @weather
522
522
  Forecast for Lisbon tomorrow?
523
523
  ```
524
524
 
525
+ A report may carry one more line after the title, `advantage: {json}`: what
526
+ has been shown to work (`{"edges":[{"label","edge","n"}],"open":[],"settled":[],
527
+ "testing":[],"kept":[],"dropped":[],"explore":0.2}`, at most 8 edges, highest
528
+ first, 4000 characters). Pass `advantage: {edges, explore}` on the report and
529
+ `formatWorkReport` writes it (dropping the lowest-n edges if it ever runs over);
530
+ `parseWorkReport` and `parseAdvantage` read it back, and a missing or malformed
531
+ line is simply no advantage. Salt's plan sheet shows the edges under "What's
532
+ working".
533
+
525
534
  Reports are sent `quiet` (no push notification) except `waiting`. Build one
526
535
  yourself with `createWorkReporter(client).report(identity, {chatId,
527
536
  requesterId}, {id, status, title, detail})`; it never throws, so a report that
package/dist/client.d.ts CHANGED
@@ -1072,7 +1072,7 @@ type RequestFn = <T>(method: string, path: string, apiKey: string, body?: unknow
1072
1072
  idempotencyKey?: string;
1073
1073
  }) => Promise<T>;
1074
1074
  /** Sent as `X-Salt-Client` on every request. Kept equal to package.json's version (a test checks). */
1075
- export declare const SDK_VERSION = "0.25.0";
1075
+ export declare const SDK_VERSION = "0.26.0";
1076
1076
  export declare function createSaltClient(options: SaltClientOptions): {
1077
1077
  actFor: (principalId: SaltId, opts?: ActForOptions) => { [K in keyof ReturnType<(request: RequestFn) => {
1078
1078
  /** A chat's members (with public keys), for encrypting a reply to everyone who should read it. */
package/dist/client.js CHANGED
@@ -135,7 +135,7 @@ class RecipientContactsOnlyError extends SaltApiError {
135
135
  }
136
136
  exports.RecipientContactsOnlyError = RecipientContactsOnlyError;
137
137
  /** Sent as `X-Salt-Client` on every request. Kept equal to package.json's version (a test checks). */
138
- exports.SDK_VERSION = "0.25.0";
138
+ exports.SDK_VERSION = "0.26.0";
139
139
  const CLIENT_HEADER = `salt-agent-sdk/${exports.SDK_VERSION}`;
140
140
  function createSaltClient(options) {
141
141
  const host = options.host.replace(/\/$/, "");
package/dist/work.d.ts CHANGED
@@ -9,6 +9,27 @@ export declare const WORK_KINDS: readonly WorkKind[];
9
9
  export declare const WORK_REPEATS: readonly WorkRepeat[];
10
10
  export declare const MAX_WORK_TITLE = 140;
11
11
  export declare const MAX_WORK_DETAIL = 500;
12
+ export declare const MAX_ADVANTAGE_CHARS = 4000;
13
+ export declare const MAX_ADVANTAGE_EDGES = 8;
14
+ export interface AdvantageEdge {
15
+ /** The kind of move, in words or snake_case labels ("post_to_profile · hacker_news · founders"). */
16
+ label: string;
17
+ /** How many times the agent's average result it earns (1.8 = 1.8x). */
18
+ edge: number;
19
+ /** Moves behind it. */
20
+ n: number;
21
+ }
22
+ export interface Advantage {
23
+ edges: AdvantageEdge[];
24
+ /** Phase 2 keys: written empty today, kept as sent when read. */
25
+ open?: unknown[];
26
+ settled?: unknown[];
27
+ testing?: unknown[];
28
+ kept?: unknown[];
29
+ dropped?: unknown[];
30
+ /** Share of effort spent trying new things, 0 to 1. */
31
+ explore?: number;
32
+ }
12
33
  export interface WorkReport {
13
34
  id: string;
14
35
  status: WorkStatus;
@@ -23,9 +44,17 @@ export interface WorkReport {
23
44
  repeat?: WorkRepeat;
24
45
  /** The confirmed transfer behind money work (`transfer=<id>`); salt-fe reads the receipt row from it. */
25
46
  transfer?: string;
47
+ /** What has been shown to work, as the `advantage:` line after the title. */
48
+ advantage?: Advantage;
26
49
  }
27
50
  /** A fresh id for one piece of work. */
28
51
  export declare function newWorkId(): string;
52
+ /** The `advantage:` JSON for a report: edges sorted by edge (highest first),
53
+ * at most 8, the lowest-n edge dropped until it fits 4000 characters, the
54
+ * phase 2 keys present and empty. Null when the input has no usable shape. */
55
+ export declare function formatAdvantage(advantage: Advantage | null | undefined): string | null;
56
+ /** The value of an `advantage:` line, as an Advantage, or null (bad JSON, wrong shape, over the cap). */
57
+ export declare function parseAdvantage(value: string): Advantage | null;
29
58
  /** The plaintext of one report. Throws on a malformed id or status. */
30
59
  export declare function formatWorkReport(report: WorkReport): string;
31
60
  /** The report in a plaintext, or null when it is not one. */
@@ -1 +1 @@
1
- {"version":3,"file":"work.d.ts","sourceRoot":"","sources":["../src/work.ts"],"names":[],"mappings":"AAuCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,WAAW,CAAC;AAC/F,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,MAAM,CAAC;AAC7C,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEhF,eAAO,MAAM,aAAa,EAAE,SAAS,UAAU,EAAuE,CAAC;AACvH,eAAO,MAAM,UAAU,EAAE,SAAS,QAAQ,EAA2B,CAAC;AACtE,eAAO,MAAM,YAAY,EAAE,SAAS,UAAU,EAAyD,CAAC;AAExG,eAAO,MAAM,cAAc,MAAM,CAAC;AAClC,eAAO,MAAM,eAAe,MAAM,CAAC;AAEnC,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,iDAAiD;IACjD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,y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ACxC,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAKD;;+EAE+E;AAC/E,wBAAgB,eAAe,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CA0BtF;AAED,yGAAyG;AACzG,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAgB9D;AAID,uEAAuE;AACvE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAe3D;AAED,6DAA6D;AAC7D,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CA2BpE;AAED;;;;mDAImD;AACnD,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGhE;AAED,MAAM,WAAW,UAAU;IACzB,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;CACrB;AAOD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,UAAU;qBA6BrB,aAAa,UAAU,UAAU,cAAc,UAAU,KAAG,OAAO,CAAC,OAAO,CAAC;;EAgB3G;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
package/dist/work.js CHANGED
@@ -28,6 +28,14 @@
28
28
  // after is detail. The web app's parser lives in salt-fe
29
29
  // `src/utilities/work.js`; keep the two in step.
30
30
  //
31
+ // An optional `advantage: {json}` line may follow the title (DYNAMIC_ADVANTAGE
32
+ // phase 1): what has been shown to work, `{"edges":[{"label","edge","n"}],
33
+ // "open":[],"settled":[],"testing":[],"kept":[],"dropped":[],"explore":0.2}`,
34
+ // at most 8 edges sorted by edge, 4000 characters (formatAdvantage drops the
35
+ // lowest-n edges until it fits). Phase 1 fills `edges` and `explore` only.
36
+ // salt-fe reads it in `parseAdvantage`; Grains writes the same line into the
37
+ // reports it makes.
38
+ //
31
39
  // Cancel (person -> agent), a WHOLE message on its own, sent into the same
32
40
  // lane a `scheduled` report came from:
33
41
  //
@@ -70,8 +78,10 @@ var __importStar = (this && this.__importStar) || (function () {
70
78
  };
71
79
  })();
72
80
  Object.defineProperty(exports, "__esModule", { value: true });
73
- exports.MAX_WORK_DETAIL = exports.MAX_WORK_TITLE = exports.WORK_REPEATS = exports.WORK_KINDS = exports.WORK_STATUSES = void 0;
81
+ exports.MAX_ADVANTAGE_EDGES = exports.MAX_ADVANTAGE_CHARS = exports.MAX_WORK_DETAIL = exports.MAX_WORK_TITLE = exports.WORK_REPEATS = exports.WORK_KINDS = exports.WORK_STATUSES = void 0;
74
82
  exports.newWorkId = newWorkId;
83
+ exports.formatAdvantage = formatAdvantage;
84
+ exports.parseAdvantage = parseAdvantage;
75
85
  exports.formatWorkReport = formatWorkReport;
76
86
  exports.parseWorkReport = parseWorkReport;
77
87
  exports.parseWorkCancel = parseWorkCancel;
@@ -84,6 +94,8 @@ exports.WORK_KINDS = ["delegation", "task"];
84
94
  exports.WORK_REPEATS = ["hourly", "daily", "weekdays", "weekly", "monthly"];
85
95
  exports.MAX_WORK_TITLE = 140;
86
96
  exports.MAX_WORK_DETAIL = 500;
97
+ exports.MAX_ADVANTAGE_CHARS = 4000;
98
+ exports.MAX_ADVANTAGE_EDGES = 8;
87
99
  const ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
88
100
  const HANDLE_RE = /^[A-Za-z0-9_.-]{1,40}$/;
89
101
  const MARKER_RE = /^\[\[SALT-WORK ([^\]\n]*)\]\]\n?/;
@@ -94,6 +106,65 @@ function newWorkId() {
94
106
  return `w_${(0, node_crypto_1.randomBytes)(6).toString("hex")}`;
95
107
  }
96
108
  const oneLine = (text, max) => (text || "").replace(/\s+/g, " ").trim().slice(0, max);
109
+ /** The `advantage:` JSON for a report: edges sorted by edge (highest first),
110
+ * at most 8, the lowest-n edge dropped until it fits 4000 characters, the
111
+ * phase 2 keys present and empty. Null when the input has no usable shape. */
112
+ function formatAdvantage(advantage) {
113
+ if (!advantage || !Array.isArray(advantage.edges))
114
+ return null;
115
+ const edges = advantage.edges
116
+ .map((e) => ({ label: oneLine(e && e.label, 120), edge: Number(e && e.edge), n: Number(e && e.n) }))
117
+ .filter((e) => e.label && Number.isFinite(e.edge) && e.edge > 0 && Number.isFinite(e.n) && e.n >= 0)
118
+ .sort((a, b) => b.edge - a.edge)
119
+ .slice(0, exports.MAX_ADVANTAGE_EDGES);
120
+ const explore = Number(advantage.explore);
121
+ const build = () => JSON.stringify({
122
+ edges,
123
+ open: [],
124
+ settled: [],
125
+ testing: [],
126
+ kept: [],
127
+ dropped: [],
128
+ explore: Number.isFinite(explore) ? explore : 0,
129
+ });
130
+ let json = build();
131
+ while (json.length > exports.MAX_ADVANTAGE_CHARS && edges.length) {
132
+ let lowest = 0;
133
+ edges.forEach((e, i) => { if (e.n < edges[lowest].n)
134
+ lowest = i; });
135
+ edges.splice(lowest, 1);
136
+ json = build();
137
+ }
138
+ return json.length > exports.MAX_ADVANTAGE_CHARS ? null : json;
139
+ }
140
+ /** The value of an `advantage:` line, as an Advantage, or null (bad JSON, wrong shape, over the cap). */
141
+ function parseAdvantage(value) {
142
+ if (!value || value.length > exports.MAX_ADVANTAGE_CHARS)
143
+ return null;
144
+ let raw;
145
+ try {
146
+ raw = JSON.parse(value);
147
+ }
148
+ catch {
149
+ return null;
150
+ }
151
+ if (!raw || typeof raw !== "object" || Array.isArray(raw) || !Array.isArray(raw.edges))
152
+ return null;
153
+ const edges = raw.edges
154
+ .map((e) => ({ label: oneLine(e && e.label, 120), edge: Number(e && e.edge), n: Number(e && e.n) }))
155
+ .filter((e) => e.label && Number.isFinite(e.edge) && e.edge > 0 && Number.isFinite(e.n) && e.n >= 0)
156
+ .slice(0, exports.MAX_ADVANTAGE_EDGES);
157
+ const advantage = { edges };
158
+ for (const key of ["open", "settled", "testing", "kept", "dropped"]) {
159
+ if (Array.isArray(raw[key]))
160
+ advantage[key] = raw[key];
161
+ }
162
+ const explore = Number(raw.explore);
163
+ if (raw.explore != null && Number.isFinite(explore))
164
+ advantage.explore = explore;
165
+ return advantage;
166
+ }
167
+ const ADVANTAGE_LINE_RE = /^advantage:[ \t]*(.*)$/;
97
168
  /** The plaintext of one report. Throws on a malformed id or status. */
98
169
  function formatWorkReport(report) {
99
170
  if (!ID_RE.test(report.id || ""))
@@ -116,7 +187,8 @@ function formatWorkReport(report) {
116
187
  if (!title)
117
188
  throw new Error("A work report needs a title.");
118
189
  const detail = (report.detail || "").trim().slice(0, exports.MAX_WORK_DETAIL);
119
- return `[[SALT-WORK ${attrs.join(" ")}]]\n${title}${detail ? `\n${detail}` : ""}`;
190
+ const advantage = formatAdvantage(report.advantage);
191
+ return `[[SALT-WORK ${attrs.join(" ")}]]\n${title}${advantage ? `\nadvantage: ${advantage}` : ""}${detail ? `\n${detail}` : ""}`;
120
192
  }
121
193
  /** The report in a plaintext, or null when it is not one. */
122
194
  function parseWorkReport(plaintext) {
@@ -144,7 +216,18 @@ function parseWorkReport(plaintext) {
144
216
  report.repeat = attrs.repeat;
145
217
  if (attrs.transfer && ID_RE.test(attrs.transfer))
146
218
  report.transfer = attrs.transfer;
147
- const detail = rest.join("\n").trim();
219
+ const kept = [];
220
+ rest.forEach((line) => {
221
+ const m = ADVANTAGE_LINE_RE.exec(line.trim());
222
+ if (!m) {
223
+ kept.push(line);
224
+ return;
225
+ }
226
+ const advantage = parseAdvantage(m[1].trim());
227
+ if (advantage)
228
+ report.advantage = advantage;
229
+ });
230
+ const detail = kept.join("\n").trim();
148
231
  if (detail)
149
232
  report.detail = detail;
150
233
  return report;
package/dist/work.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"work.js","sourceRoot":"","sources":["../src/work.ts"],"names":[],"mappings":";AAAA,6EAA6E;AAC7E,6EAA6E;AAC7E,gDAAgD;AAChD,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,0EAA0E;AAC1E,6EAA6E;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AC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;AACjD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "salt-agent-sdk",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "description": "Plumbing for building Salt (saltapp.ai) agents: webhook receiving/routing, PGP encrypt/decrypt, a typed REST client, and card builders. Bring your own agent logic -- this handles everything Salt-protocol-specific.",
5
5
  "license": "MIT",
6
6
  "author": "0x0000F8 <0000F8@proton.me>",
package/dist/lattice.d.ts DELETED
@@ -1,206 +0,0 @@
1
- import { type SaltId } from "./ids.js";
2
- /**
3
- * How long request_personal_data waits for a release before reporting
4
- * "pending" instead of "released". This bounds how long ONE chat turn keeps
5
- * whoever's waiting on the agent hanging -- it is NOT protecting against
6
- * Salt's own webhook delivery timeout: webhook.ts acknowledges salt-api's
7
- * POST before ever calling dispatch(), so nothing here is on the clock for
8
- * that deadline. A "pending" result past this is the normal case, not an
9
- * error -- see actions.ts's request_personal_data and onRelease/
10
- * onLatticeRelease for what happens when the answer arrives afterward.
11
- */
12
- export declare const LATTICE_REQUEST_TIMEOUT_MS = 15000;
13
- export declare const REQUEST_MARKER_RE: RegExp;
14
- export declare const RELEASE_MARKER_RE: RegExp;
15
- export declare const PROPOSE_MARKER_RE: RegExp;
16
- export interface LatticeFact {
17
- path: string;
18
- type: string;
19
- field: string;
20
- /** A JSON primitive (string/number/boolean/null) -- normalizeFact rejects an object or array here. */
21
- value: string | number | boolean | null;
22
- /** "you" or "agent" -- WHICH agent wrote it is deliberately never disclosed (PROTOCOL.md). */
23
- author: "you" | "agent";
24
- updated: number;
25
- }
26
- /** The JSON body of a [[SALT-LATTICE-RELEASE]] message, either shape (a
27
- * reply to one request, or a standing push -- see the module comment). */
28
- export interface ReleaseBody {
29
- facts: LatticeFact[];
30
- /** Present on an ordinary reply to a request; absent on a standing push. */
31
- request_id?: string;
32
- /** Present only on a standing push. */
33
- grant_id?: string;
34
- /** Present only on a standing push: facts changed since this sequence number. */
35
- since_seq?: number;
36
- }
37
- export interface LatticeRelease {
38
- /** The release message's own id (for the disclosure log) -- NOT the request id it answers. */
39
- id: string;
40
- /** Set to a grant id for a standing push; absent for an ordinary reply. */
41
- standing?: string;
42
- /** The chat and sender this release actually arrived from (Salt-authenticated, not attacker-controlled). */
43
- chatId: SaltId;
44
- senderId: SaltId;
45
- body: ReleaseBody;
46
- }
47
- export interface BuildRequestInput {
48
- /** One plain sentence, shown to the person before they decide -- PROTOCOL.md's Request. */
49
- purpose: string;
50
- /** Selectors, e.g. "preferences.food.cuisine.*" -- only what the agent's grant names is ever released; asking for more is not an error. */
51
- asks: string[];
52
- }
53
- /**
54
- * Mints a fresh request id and its wire text. Send `text` as an ordinary
55
- * encrypted chat message into the current chat (or the agent's private
56
- * lane); the phone answers it -- in a group, inside a sidechain it opens
57
- * with this agent, never in the room (PROTOCOL.md R6).
58
- */
59
- export declare function buildRequest(input: BuildRequestInput): {
60
- id: string;
61
- text: string;
62
- };
63
- export interface LatticeProposalInput {
64
- /** A closed-schema type name (PROTOCOL.md) -- an unknown type or field is silently dropped on the phone, never an error here or there. */
65
- type: string;
66
- parent_name?: string;
67
- fields: Record<string, unknown>;
68
- }
69
- /**
70
- * Builds a [[SALT-LATTICE-PROPOSE]] message suggesting new facts. Always
71
- * lands `pending` on the phone unless the agent's grant trusts its writes
72
- * to that compartment (PROTOCOL.md R3) -- there is no reply to wait for,
73
- * so unlike buildRequest this returns only the wire text.
74
- */
75
- export declare function buildProposal(proposals: LatticeProposalInput[]): string;
76
- /** A single release's fact count is capped here -- not rejected outright,
77
- * just bounded, since an over-long but otherwise well-formed release isn't
78
- * a protocol violation the way a malformed entry is (see normalizeFact). */
79
- export declare const MAX_FACTS_PER_RELEASE = 200;
80
- /** A fact's string value is capped to this many characters, after marker
81
- * stripping (see sanitizeFactValue) -- bounds how much untrusted text from
82
- * the other end of the wire can reach a model in one fact. */
83
- export declare const MAX_FACT_VALUE_LENGTH = 2000;
84
- /**
85
- * Splits an incoming plaintext into its release marker's id, optional
86
- * standing grant id, and parsed JSON body -- or null when `plaintext` isn't
87
- * a (well-formed, in-protocol) lattice release at all. Returns null for an
88
- * unparseable or malformed body, and also for a body that is neither an
89
- * ordinary reply (`request_id`) nor a standing push (`standing=` on the
90
- * marker line AND `grant_id` in the body) -- PROTOCOL.md says a release is
91
- * "always a reply to a request id" unless it's a standing push, so anything
92
- * else is out-of-protocol. Deliberate in all these cases: it's safer to let
93
- * a corrupt or nonsensical release fall through as ordinary (harmless)
94
- * message text than to silently act on it. A standing push's marker-line
95
- * `standing=<grant id>` and its body's `grant_id` must name the SAME grant
96
- * -- PROTOCOL.md's own example shows them matching, and disagreeing values
97
- * are simply invalid rather than a case to guess between (whoever
98
- * eventually checks `grant_id` against this agent's actual grants -- see
99
- * webhook.ts's onLatticeRelease verification -- must be checking the one
100
- * value the marker itself also claims).
101
- */
102
- export declare function parseRelease(plaintext: string): {
103
- id: string;
104
- standing?: string;
105
- body: ReleaseBody;
106
- } | null;
107
- export declare function hasPending(id: string): boolean;
108
- export interface RegisterBinding {
109
- /** The chat the request was actually sent into. */
110
- chatId: SaltId;
111
- /** The person the request was actually addressed to -- see actions.ts's request_personal_data, which resolves this to one specific chat member even in a group. */
112
- senderId: SaltId;
113
- timeoutMs: number;
114
- }
115
- /**
116
- * Registers a wait for the release answering request `id`, bound to the
117
- * exact chat and person it was sent to. Only a release arriving from THAT
118
- * chat and THAT sender can resolve it (see classifyRelease) -- a request's
119
- * plaintext id is visible to every current member of the chat it's sent
120
- * into (see actions.ts), so the id alone must never be sufficient to claim
121
- * a release.
122
- *
123
- * Resolves with that release's parsed body, or rejects once `timeoutMs`
124
- * elapses -- rejecting is an expected outcome, not a protocol error:
125
- * PROTOCOL.md says the phone only answers when the app is next open, which
126
- * routinely outlasts one webhook round-trip. Throws synchronously (before
127
- * any caller does anything else) if `id` already has a pending wait.
128
- */
129
- export declare function register(id: string, binding: RegisterBinding): Promise<ReleaseBody>;
130
- /**
131
- * Clears a pending wait without settling its promise -- used when sending
132
- * the request message itself fails right after register() ran, so the
133
- * registry entry doesn't leak (the caller throws its own error instead).
134
- */
135
- export declare function cancel(id: string): void;
136
- type ReleaseHandler = (release: LatticeRelease) => void | Promise<void>;
137
- /**
138
- * Subscribes to releases that arrive with nothing waiting on them: a late
139
- * reply (the request already timed out) or a standing push (there was
140
- * never a request to begin with). Returns an unsubscribe function.
141
- *
142
- * UNVERIFIED: lattice.ts has no REST client and no concept of a grant, so a
143
- * handler here fires for ANY sender in ANY chat with no check that they
144
- * actually hold a live grant to this agent. webhook.ts's `onLatticeRelease`
145
- * option is the verified, recommended path for exactly this case (it
146
- * fetches this agent's live grants and checks the sender is human and,
147
- * for a standing push, that `grant_id` names one, before ever calling your
148
- * handler) -- reach for this lower-level hook only if you're bypassing
149
- * webhook.ts entirely, and do your own equivalent check.
150
- *
151
- * A handler may be async. Either a synchronous throw or a rejected promise
152
- * is swallowed -- like every other fire-and-forget hook in this SDK, a bug
153
- * in a consumer's handler must not take down webhook processing (an
154
- * unhandled rejection crashes the process on modern Node defaults).
155
- */
156
- export declare function onRelease(handler: ReleaseHandler): () => void;
157
- export type ReleaseOutcome = {
158
- kind: "not-a-release";
159
- } | {
160
- kind: "matched";
161
- } | {
162
- kind: "refused";
163
- } | {
164
- kind: "unmatched";
165
- release: LatticeRelease;
166
- };
167
- /**
168
- * Call right after decrypting an inbound message, before deciding whether
169
- * to run a fresh reply cycle -- the same spot webhook.ts calls
170
- * delegations.resolveIfPending (and what webhook.ts itself calls, to also
171
- * learn about an "unmatched" release for its onLatticeRelease option).
172
- *
173
- * - "not-a-release": `plaintext` isn't lattice wire protocol at all --
174
- * including this identity's own outgoing requests/proposals, which never
175
- * match RELEASE_MARKER_RE, and any genuinely unrelated message.
176
- * - "matched": `chatId`/`senderId` agree with a live register() wait for
177
- * this release's `request_id` -- that wait's promise is resolved directly;
178
- * there is nothing further for a caller to do.
179
- * - "refused": this release names a request id a wait IS pending for, but
180
- * `chatId`/`senderId` don't match what register() bound it to -- e.g. a
181
- * bystander who merely saw the plaintext request id (see
182
- * RegisterBinding's doc comment) replaying it as a forged release. The
183
- * live wait is untouched (still running, still resolvable by the real
184
- * answer); this message is left for the caller to process as ordinary,
185
- * harmless text -- it must NOT be treated as Lattice traffic.
186
- * - "unmatched": a genuine late reply or standing push -- fired to
187
- * onRelease() before this returns.
188
- */
189
- export declare function classifyRelease(chatId: SaltId, senderId: SaltId, plaintext: string): ReleaseOutcome;
190
- /**
191
- * Boolean convenience wrapper over classifyRelease, mirroring
192
- * delegations.resolveIfPending(chatId, senderId, plaintext)'s shape for a
193
- * simple caller that doesn't need an "unmatched" release's details (e.g. a
194
- * custom integration built directly on lattice.ts, without webhook.ts).
195
- * True for "matched" and "unmatched" (don't treat `plaintext` as a fresh
196
- * prompt); false for "not-a-release" AND "refused" (a forged/misdirected
197
- * release is left to fall through exactly like ordinary text, same as
198
- * "not-a-release" -- see classifyRelease's doc comment).
199
- *
200
- * webhook.ts itself calls classifyRelease directly instead of this, since
201
- * it also needs an "unmatched" release's details (chat/sender/body) to
202
- * offer to its own onLatticeRelease option.
203
- */
204
- export declare function resolveIfPending(chatId: SaltId, senderId: SaltId, plaintext: string): boolean;
205
- export {};
206
- //# sourceMappingURL=lattice.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lattice.d.ts","sourceRoot":"","sources":["../src/lattice.ts"],"names":[],"mappings":"AAgDA,OAAO,EAA4B,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAEjE;;;;;;;;;GASG;AACH,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAOjD,eAAO,MAAM,iBAAiB,QAA2E,CAAC;AAC1G,eAAO,MAAM,iBAAiB,QAAgG,CAAC;AAC/H,eAAO,MAAM,iBAAiB,QAA2E,CA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;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,cAAc,CAqBnG;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAG7F"}
package/dist/lattice.js DELETED
@@ -1,366 +0,0 @@
1
- "use strict";
2
- // Lets a hosted identity ask the person it's chatting with for personal
3
- // facts from Lattice -- their private, on-device knowledge graph -- and get
4
- // an answer back over a real Salt message, the same way delegations.ts gets
5
- // a reply from another agent. See ../../salt-lattice/docs/PROTOCOL.md for
6
- // the wire contract this implements; nothing here decides WHETHER a fact is
7
- // released (that is entirely the phone's own grant evaluation, offline and
8
- // invisible to the server) -- this module only builds the outgoing
9
- // markers, parses the incoming one, and matches a release back to the
10
- // request it answers.
11
- //
12
- // Three message shapes ride inside encrypted plaintext, one line then a
13
- // JSON body, exactly like [[SALT-DELEGATION]]:
14
- // [[SALT-LATTICE-REQUEST id=<ulid>]] agent -> person, asking
15
- // [[SALT-LATTICE-RELEASE id=<ulid> [standing=<grant id>]]] person's phone -> agent, answering
16
- // [[SALT-LATTICE-PROPOSE id=<ulid>]] agent -> person's phone, suggesting a fact
17
- //
18
- // A release is matched back to its request by `request_id` IN ITS JSON BODY
19
- // -- never by the release's own `id`, which only identifies that one
20
- // disclosure for the log -- AND by the chat and sender it was actually
21
- // registered against (see register()/classifyRelease()). A request's
22
- // plaintext id is visible to every current member of whatever chat it was
23
- // sent into (see actions.ts's request_personal_data), so a request id alone
24
- // is not a secret; the chat+sender binding is what stops a bystander who
25
- // merely SAW that id from forging a release and having it accepted as the
26
- // real recipient's answer.
27
- //
28
- // Three outcomes a release-shaped message can produce, besides "not a
29
- // release at all" (see ReleaseOutcome/classifyRelease):
30
- // - matched: chat and sender agree with what register() bound to this
31
- // request id. Resolves that wait's promise directly; nothing else to do.
32
- // - refused: names a request id this process really is waiting on, but
33
- // the chat or the sender don't match the binding -- a forged or
34
- // misdirected release. The live wait keeps waiting; this message is
35
- // left for the caller to fall through as ordinary (harmless) text.
36
- // - unmatched (late or standing): a release-shaped message with no live
37
- // wait to resolve -- either a genuinely late reply (the request already
38
- // timed out; the phone only answers when the app is next open, which
39
- // routinely outlasts one webhook round-trip) or an opted-in standing
40
- // push, which never had a request to begin with. Unlike "matched",
41
- // THIS module never authenticates who sent it -- lattice.ts has no
42
- // REST client and no concept of a grant. Reaches onRelease() (raw,
43
- // unverified) and, via webhook.ts's onLatticeRelease option, a
44
- // consumer's own follow-up logic -- webhook.ts is what verifies the
45
- // sender is human and holds a live grant (and, for standing, that it's
46
- // the grant named) before that option ever fires, dropping and logging
47
- // otherwise. Reaching onRelease/onLatticeRelease at all is not itself a
48
- // trust signal.
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.MAX_FACT_VALUE_LENGTH = exports.MAX_FACTS_PER_RELEASE = exports.PROPOSE_MARKER_RE = exports.RELEASE_MARKER_RE = exports.REQUEST_MARKER_RE = exports.LATTICE_REQUEST_TIMEOUT_MS = void 0;
51
- exports.buildRequest = buildRequest;
52
- exports.buildProposal = buildProposal;
53
- exports.parseRelease = parseRelease;
54
- exports.hasPending = hasPending;
55
- exports.register = register;
56
- exports.cancel = cancel;
57
- exports.onRelease = onRelease;
58
- exports.classifyRelease = classifyRelease;
59
- exports.resolveIfPending = resolveIfPending;
60
- const ids_js_1 = require("./ids.js");
61
- /**
62
- * How long request_personal_data waits for a release before reporting
63
- * "pending" instead of "released". This bounds how long ONE chat turn keeps
64
- * whoever's waiting on the agent hanging -- it is NOT protecting against
65
- * Salt's own webhook delivery timeout: webhook.ts acknowledges salt-api's
66
- * POST before ever calling dispatch(), so nothing here is on the clock for
67
- * that deadline. A "pending" result past this is the normal case, not an
68
- * error -- see actions.ts's request_personal_data and onRelease/
69
- * onLatticeRelease for what happens when the answer arrives afterward.
70
- */
71
- exports.LATTICE_REQUEST_TIMEOUT_MS = 15_000;
72
- // Embed ULID_RE's character class without its ^...$ anchors, so the id
73
- // group inside each marker regex stays in lock-step with what newUlid()
74
- // actually produces.
75
- const ULID_SRC = ids_js_1.ULID_RE.source.slice(1, -1);
76
- exports.REQUEST_MARKER_RE = new RegExp(`^\\[\\[SALT-LATTICE-REQUEST id=(${ULID_SRC})\\]\\]\\n`, "i");
77
- exports.RELEASE_MARKER_RE = new RegExp(`^\\[\\[SALT-LATTICE-RELEASE id=(${ULID_SRC})(?: standing=(\\S+))?\\]\\]\\n`, "i");
78
- exports.PROPOSE_MARKER_RE = new RegExp(`^\\[\\[SALT-LATTICE-PROPOSE id=(${ULID_SRC})\\]\\]\\n`, "i");
79
- /**
80
- * Mints a fresh request id and its wire text. Send `text` as an ordinary
81
- * encrypted chat message into the current chat (or the agent's private
82
- * lane); the phone answers it -- in a group, inside a sidechain it opens
83
- * with this agent, never in the room (PROTOCOL.md R6).
84
- */
85
- function buildRequest(input) {
86
- const id = (0, ids_js_1.newUlid)();
87
- const body = JSON.stringify({ purpose: input.purpose, asks: input.asks });
88
- return { id, text: `[[SALT-LATTICE-REQUEST id=${id}]]\n${body}` };
89
- }
90
- /**
91
- * Builds a [[SALT-LATTICE-PROPOSE]] message suggesting new facts. Always
92
- * lands `pending` on the phone unless the agent's grant trusts its writes
93
- * to that compartment (PROTOCOL.md R3) -- there is no reply to wait for,
94
- * so unlike buildRequest this returns only the wire text.
95
- */
96
- function buildProposal(proposals) {
97
- const id = (0, ids_js_1.newUlid)();
98
- const body = JSON.stringify({ proposals });
99
- return `[[SALT-LATTICE-PROPOSE id=${id}]]\n${body}`;
100
- }
101
- const FACT_AUTHORS = new Set(["you", "agent"]);
102
- // PROTOCOL.md's exact fact shape. Validated field-by-field, not just "facts
103
- // is an array": a forged or buggy release could otherwise hand a model
104
- // whatever shape it likes under `facts[]`, and (pre-binding-fix) that used
105
- // to reach a calling tool's "released" result unfiltered. One malformed
106
- // entry rejects the WHOLE body (returns null), the same fail-closed
107
- // convention as an unparseable body -- a partially-trusted release is worse
108
- // than a dropped one.
109
- function isPrimitive(value) {
110
- return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
111
- }
112
- /** A single release's fact count is capped here -- not rejected outright,
113
- * just bounded, since an over-long but otherwise well-formed release isn't
114
- * a protocol violation the way a malformed entry is (see normalizeFact). */
115
- exports.MAX_FACTS_PER_RELEASE = 200;
116
- /** A fact's string value is capped to this many characters, after marker
117
- * stripping (see sanitizeFactValue) -- bounds how much untrusted text from
118
- * the other end of the wire can reach a model in one fact. */
119
- exports.MAX_FACT_VALUE_LENGTH = 2_000;
120
- // Every wire marker this SDK recognizes starts with this exact two-bracket
121
- // prefix, anchored at the very start of a plaintext (see the *_MARKER_RE
122
- // definitions above -- none of them carry the `m` flag). A fact's value is
123
- // untrusted content from the other end of the wire; without this, a value
124
- // containing literal "[[SALT-...]]" text could later start some OTHER
125
- // outbound message built by echoing the fact back (e.g. "the person's
126
- // favorite cuisine is <value>") and be mistaken for a genuine protocol
127
- // marker by whatever receives it. Breaks the bracket pair rather than
128
- // deleting the text outright, so the value stays legible.
129
- const MARKER_TEXT_RE = /\[\[SALT-/g;
130
- function sanitizeFactValue(value) {
131
- if (typeof value !== "string")
132
- return value;
133
- const stripped = value.replace(MARKER_TEXT_RE, "[SALT-");
134
- return stripped.length > exports.MAX_FACT_VALUE_LENGTH ? stripped.slice(0, exports.MAX_FACT_VALUE_LENGTH) : stripped;
135
- }
136
- function normalizeFact(raw) {
137
- if (!raw || typeof raw !== "object")
138
- return null;
139
- const f = raw;
140
- if (typeof f.path !== "string" || typeof f.type !== "string" || typeof f.field !== "string")
141
- return null;
142
- if (typeof f.author !== "string" || !FACT_AUTHORS.has(f.author))
143
- return null;
144
- if (typeof f.updated !== "number")
145
- return null;
146
- if (!isPrimitive(f.value))
147
- return null;
148
- return { path: f.path, type: f.type, field: f.field, value: sanitizeFactValue(f.value), author: f.author, updated: f.updated };
149
- }
150
- function normalizeReleaseBody(parsed) {
151
- if (!parsed || typeof parsed !== "object")
152
- return null;
153
- const obj = parsed;
154
- if (!Array.isArray(obj.facts))
155
- return null;
156
- const facts = [];
157
- for (const raw of obj.facts) {
158
- const fact = normalizeFact(raw);
159
- if (!fact)
160
- return null;
161
- facts.push(fact);
162
- }
163
- const body = { facts: facts.slice(0, exports.MAX_FACTS_PER_RELEASE) };
164
- if (typeof obj.request_id === "string")
165
- body.request_id = obj.request_id;
166
- if (typeof obj.grant_id === "string")
167
- body.grant_id = obj.grant_id;
168
- if (typeof obj.since_seq === "number")
169
- body.since_seq = obj.since_seq;
170
- return body;
171
- }
172
- /**
173
- * Splits an incoming plaintext into its release marker's id, optional
174
- * standing grant id, and parsed JSON body -- or null when `plaintext` isn't
175
- * a (well-formed, in-protocol) lattice release at all. Returns null for an
176
- * unparseable or malformed body, and also for a body that is neither an
177
- * ordinary reply (`request_id`) nor a standing push (`standing=` on the
178
- * marker line AND `grant_id` in the body) -- PROTOCOL.md says a release is
179
- * "always a reply to a request id" unless it's a standing push, so anything
180
- * else is out-of-protocol. Deliberate in all these cases: it's safer to let
181
- * a corrupt or nonsensical release fall through as ordinary (harmless)
182
- * message text than to silently act on it. A standing push's marker-line
183
- * `standing=<grant id>` and its body's `grant_id` must name the SAME grant
184
- * -- PROTOCOL.md's own example shows them matching, and disagreeing values
185
- * are simply invalid rather than a case to guess between (whoever
186
- * eventually checks `grant_id` against this agent's actual grants -- see
187
- * webhook.ts's onLatticeRelease verification -- must be checking the one
188
- * value the marker itself also claims).
189
- */
190
- function parseRelease(plaintext) {
191
- const match = exports.RELEASE_MARKER_RE.exec(plaintext);
192
- if (!match)
193
- return null;
194
- const [full, id, standing] = match;
195
- let parsed;
196
- try {
197
- parsed = JSON.parse(plaintext.slice(full.length));
198
- }
199
- catch {
200
- return null;
201
- }
202
- const body = normalizeReleaseBody(parsed);
203
- if (!body)
204
- return null;
205
- if (standing) {
206
- if (!body.grant_id || !(0, ids_js_1.sameId)(body.grant_id, standing))
207
- return null;
208
- return { id, standing, body };
209
- }
210
- if (!body.request_id)
211
- return null;
212
- return { id, body };
213
- }
214
- // Keyed by REQUEST id (the id a request_personal_data call minted and put
215
- // in the marker it sent) -- NOT by chat, unlike delegations.ts's registry,
216
- // which is chat-scoped because a chat can only be mid-delegation with one
217
- // target at a time. A person can plausibly be asked several independent
218
- // things in parallel (different tool calls, possibly from different hosted
219
- // identities sharing this process), so the request id is what safely tells
220
- // two pending waits apart.
221
- //
222
- // Lowercased on every store/lookup -- like delegations.ts's own `mapKey` and
223
- // ids.ts's `sameId`, whose comments say why: an id can cross this SDK's
224
- // boundary (webhook body, REST response, a phone's own JSON) without a
225
- // casing guarantee, and RELEASE_MARKER_RE already matches either case
226
- // (ULID_RE's `/i` flag), so the map lookup that follows it must too.
227
- const pending = new Map();
228
- const mapKey = (id) => id.toLowerCase();
229
- function hasPending(id) {
230
- return pending.has(mapKey(id));
231
- }
232
- /**
233
- * Registers a wait for the release answering request `id`, bound to the
234
- * exact chat and person it was sent to. Only a release arriving from THAT
235
- * chat and THAT sender can resolve it (see classifyRelease) -- a request's
236
- * plaintext id is visible to every current member of the chat it's sent
237
- * into (see actions.ts), so the id alone must never be sufficient to claim
238
- * a release.
239
- *
240
- * Resolves with that release's parsed body, or rejects once `timeoutMs`
241
- * elapses -- rejecting is an expected outcome, not a protocol error:
242
- * PROTOCOL.md says the phone only answers when the app is next open, which
243
- * routinely outlasts one webhook round-trip. Throws synchronously (before
244
- * any caller does anything else) if `id` already has a pending wait.
245
- */
246
- function register(id, binding) {
247
- const key = mapKey(id);
248
- if (pending.has(key)) {
249
- throw new Error("Already waiting on a release for this request.");
250
- }
251
- return new Promise((resolve, reject) => {
252
- const timer = setTimeout(() => {
253
- pending.delete(key);
254
- reject(new Error(`No release within ${Math.round(binding.timeoutMs / 1000)}s.`));
255
- }, binding.timeoutMs);
256
- pending.set(key, { chatId: binding.chatId, senderId: binding.senderId, resolve, reject, timer });
257
- });
258
- }
259
- /**
260
- * Clears a pending wait without settling its promise -- used when sending
261
- * the request message itself fails right after register() ran, so the
262
- * registry entry doesn't leak (the caller throws its own error instead).
263
- */
264
- function cancel(id) {
265
- const key = mapKey(id);
266
- const entry = pending.get(key);
267
- if (!entry)
268
- return;
269
- clearTimeout(entry.timer);
270
- pending.delete(key);
271
- }
272
- const releaseHandlers = new Set();
273
- /**
274
- * Subscribes to releases that arrive with nothing waiting on them: a late
275
- * reply (the request already timed out) or a standing push (there was
276
- * never a request to begin with). Returns an unsubscribe function.
277
- *
278
- * UNVERIFIED: lattice.ts has no REST client and no concept of a grant, so a
279
- * handler here fires for ANY sender in ANY chat with no check that they
280
- * actually hold a live grant to this agent. webhook.ts's `onLatticeRelease`
281
- * option is the verified, recommended path for exactly this case (it
282
- * fetches this agent's live grants and checks the sender is human and,
283
- * for a standing push, that `grant_id` names one, before ever calling your
284
- * handler) -- reach for this lower-level hook only if you're bypassing
285
- * webhook.ts entirely, and do your own equivalent check.
286
- *
287
- * A handler may be async. Either a synchronous throw or a rejected promise
288
- * is swallowed -- like every other fire-and-forget hook in this SDK, a bug
289
- * in a consumer's handler must not take down webhook processing (an
290
- * unhandled rejection crashes the process on modern Node defaults).
291
- */
292
- function onRelease(handler) {
293
- releaseHandlers.add(handler);
294
- return () => releaseHandlers.delete(handler);
295
- }
296
- function fireOnRelease(release) {
297
- for (const handler of releaseHandlers) {
298
- Promise.resolve()
299
- .then(() => handler(release))
300
- .catch(() => {
301
- // see onRelease's doc comment
302
- });
303
- }
304
- }
305
- /**
306
- * Call right after decrypting an inbound message, before deciding whether
307
- * to run a fresh reply cycle -- the same spot webhook.ts calls
308
- * delegations.resolveIfPending (and what webhook.ts itself calls, to also
309
- * learn about an "unmatched" release for its onLatticeRelease option).
310
- *
311
- * - "not-a-release": `plaintext` isn't lattice wire protocol at all --
312
- * including this identity's own outgoing requests/proposals, which never
313
- * match RELEASE_MARKER_RE, and any genuinely unrelated message.
314
- * - "matched": `chatId`/`senderId` agree with a live register() wait for
315
- * this release's `request_id` -- that wait's promise is resolved directly;
316
- * there is nothing further for a caller to do.
317
- * - "refused": this release names a request id a wait IS pending for, but
318
- * `chatId`/`senderId` don't match what register() bound it to -- e.g. a
319
- * bystander who merely saw the plaintext request id (see
320
- * RegisterBinding's doc comment) replaying it as a forged release. The
321
- * live wait is untouched (still running, still resolvable by the real
322
- * answer); this message is left for the caller to process as ordinary,
323
- * harmless text -- it must NOT be treated as Lattice traffic.
324
- * - "unmatched": a genuine late reply or standing push -- fired to
325
- * onRelease() before this returns.
326
- */
327
- function classifyRelease(chatId, senderId, plaintext) {
328
- const parsed = parseRelease(plaintext);
329
- if (!parsed)
330
- return { kind: "not-a-release" };
331
- if (!parsed.standing) {
332
- const key = mapKey(parsed.body.request_id); // parseRelease guarantees request_id is set for a non-standing release
333
- const entry = pending.get(key);
334
- if (entry) {
335
- if ((0, ids_js_1.sameId)(entry.chatId, chatId) && (0, ids_js_1.sameId)(entry.senderId, senderId)) {
336
- clearTimeout(entry.timer);
337
- pending.delete(key);
338
- entry.resolve(parsed.body);
339
- return { kind: "matched" };
340
- }
341
- return { kind: "refused" };
342
- }
343
- }
344
- const release = { id: parsed.id, standing: parsed.standing, chatId, senderId, body: parsed.body };
345
- fireOnRelease(release);
346
- return { kind: "unmatched", release };
347
- }
348
- /**
349
- * Boolean convenience wrapper over classifyRelease, mirroring
350
- * delegations.resolveIfPending(chatId, senderId, plaintext)'s shape for a
351
- * simple caller that doesn't need an "unmatched" release's details (e.g. a
352
- * custom integration built directly on lattice.ts, without webhook.ts).
353
- * True for "matched" and "unmatched" (don't treat `plaintext` as a fresh
354
- * prompt); false for "not-a-release" AND "refused" (a forged/misdirected
355
- * release is left to fall through exactly like ordinary text, same as
356
- * "not-a-release" -- see classifyRelease's doc comment).
357
- *
358
- * webhook.ts itself calls classifyRelease directly instead of this, since
359
- * it also needs an "unmatched" release's details (chat/sender/body) to
360
- * offer to its own onLatticeRelease option.
361
- */
362
- function resolveIfPending(chatId, senderId, plaintext) {
363
- const outcome = classifyRelease(chatId, senderId, plaintext);
364
- return outcome.kind === "matched" || outcome.kind === "unmatched";
365
- }
366
- //# sourceMappingURL=lattice.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lattice.js","sourceRoot":"","sources":["../src/lattice.ts"],"names":[],"mappings":";AAAA,wEAAwE;AACxE,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAC1E,4EAA4E;AAC5E,2EAA2E;AAC3E,mEAAmE;AACnE,sEAAsE;AACtE,sBAAsB;AACtB,EAAE;AACF,wEAAwE;AACxE,+CAA+C;AAC/C,sFAAsF;AACtF,iGAAiG;AACjG,yGAAyG;AACzG,EAAE;AACF,4EAA4E;AAC5E,qEAAqE;AACrE,uEAAuE;AACvE,qEAAqE;AACrE,0EAA0E;AAC1E,4EAA4E;AAC5E,yEAAyE;AACzE,0EAA0E;AAC1E,2BAA2B;AAC3B,EAAE;AACF,sEAAsE;AACtE,wDAAwD;AACxD,wEAAwE;AACxE,6EAA6E;AAC7E,yEAAyE;AACzE,oEAAoE;AACpE,wEAAwE;AACxE,uEAAuE;AACvE,0EAA0E;AAC1E,4EAA4E;AAC5E,yEAAyE;AACzE,yEAAyE;AACzE,uEAAuE;AACvE,uEAAuE;AACvE,uEAAuE;AACvE,mEAAmE;AACnE,wEAAwE;AACxE,2EAA2E;AAC3E,2EAA2E;AAC3E,4EAA4E;AAC5E,oBAAoB;;;AAwEpB,oCAIC;AAeD,sCAIC;AAsFD,oCAkBC;AA2BD,gCAEC;AAwBD,4BAYC;AAOD,wBAMC;AAwBD,8BAGC;AAwCD,0CAqBC;AAgBD,4CAGC;AA9XD,qCAAiE;AAEjE;;;;;;;;;GASG;AACU,QAAA,0BAA0B,GAAG,MAAM,CAAC;AAEjD,uEAAuE;AACvE,wEAAwE;AACxE,qBAAqB;AACrB,MAAM,QAAQ,GAAG,gBAAO,CAAC,MAAM,CAAC,KAAK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