@spotto/contract 1.0.70-alpha.16 → 1.0.70-alpha.18

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.
Files changed (70) hide show
  1. package/dist/ai/chat/index.d.ts +2 -0
  2. package/dist/ai/chat/index.js +19 -0
  3. package/dist/ai/chat/index.js.map +1 -0
  4. package/dist/ai/chat/request.d.ts +27 -0
  5. package/dist/ai/chat/request.js +3 -0
  6. package/dist/ai/chat/request.js.map +1 -0
  7. package/dist/ai/chat/response.d.ts +57 -0
  8. package/dist/ai/chat/response.js +11 -0
  9. package/dist/ai/chat/response.js.map +1 -0
  10. package/dist/ai/expression/request.d.ts +3 -1
  11. package/dist/ai/index.d.ts +3 -0
  12. package/dist/ai/index.js +3 -0
  13. package/dist/ai/index.js.map +1 -1
  14. package/dist/ai/semantic-query/index.d.ts +2 -0
  15. package/dist/ai/semantic-query/index.js +19 -0
  16. package/dist/ai/semantic-query/index.js.map +1 -0
  17. package/dist/ai/semantic-query/request.d.ts +30 -0
  18. package/dist/ai/semantic-query/request.js +3 -0
  19. package/dist/ai/semantic-query/request.js.map +1 -0
  20. package/dist/ai/semantic-query/response.d.ts +40 -0
  21. package/dist/ai/semantic-query/response.js +3 -0
  22. package/dist/ai/semantic-query/response.js.map +1 -0
  23. package/dist/ai/shared.d.ts +22 -0
  24. package/dist/ai/shared.js +11 -0
  25. package/dist/ai/shared.js.map +1 -0
  26. package/dist/assets/count/query.d.ts +16 -1
  27. package/dist/assets/get/query.d.ts +9 -0
  28. package/dist/index.d.ts +1 -0
  29. package/dist/index.js +1 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/semantic-queries/[id]/index.d.ts +1 -0
  32. package/dist/semantic-queries/[id]/index.js +18 -0
  33. package/dist/semantic-queries/[id]/index.js.map +1 -0
  34. package/dist/semantic-queries/[id]/patch/index.d.ts +2 -0
  35. package/dist/semantic-queries/[id]/patch/index.js +19 -0
  36. package/dist/semantic-queries/[id]/patch/index.js.map +1 -0
  37. package/dist/semantic-queries/[id]/patch/request.d.ts +20 -0
  38. package/dist/semantic-queries/[id]/patch/request.js +3 -0
  39. package/dist/semantic-queries/[id]/patch/request.js.map +1 -0
  40. package/dist/semantic-queries/[id]/patch/response.d.ts +1 -0
  41. package/dist/semantic-queries/[id]/patch/response.js +3 -0
  42. package/dist/semantic-queries/[id]/patch/response.js.map +1 -0
  43. package/dist/semantic-queries/get/index.d.ts +2 -0
  44. package/dist/semantic-queries/get/index.js +19 -0
  45. package/dist/semantic-queries/get/index.js.map +1 -0
  46. package/dist/semantic-queries/get/query.d.ts +18 -0
  47. package/dist/semantic-queries/get/query.js +3 -0
  48. package/dist/semantic-queries/get/query.js.map +1 -0
  49. package/dist/semantic-queries/get/response.d.ts +40 -0
  50. package/dist/semantic-queries/get/response.js +3 -0
  51. package/dist/semantic-queries/get/response.js.map +1 -0
  52. package/dist/semantic-queries/index.d.ts +4 -0
  53. package/dist/semantic-queries/index.js +21 -0
  54. package/dist/semantic-queries/index.js.map +1 -0
  55. package/dist/semantic-queries/post/index.d.ts +2 -0
  56. package/dist/semantic-queries/post/index.js +19 -0
  57. package/dist/semantic-queries/post/index.js.map +1 -0
  58. package/dist/semantic-queries/post/request.d.ts +36 -0
  59. package/dist/semantic-queries/post/request.js +3 -0
  60. package/dist/semantic-queries/post/request.js.map +1 -0
  61. package/dist/semantic-queries/post/response.d.ts +1 -0
  62. package/dist/semantic-queries/post/response.js +3 -0
  63. package/dist/semantic-queries/post/response.js.map +1 -0
  64. package/dist/semantic-queries/shared.d.ts +356 -0
  65. package/dist/semantic-queries/shared.js +133 -0
  66. package/dist/semantic-queries/shared.js.map +1 -0
  67. package/dist/users/home-layout/shared.d.ts +38 -4
  68. package/dist/users/home-layout/shared.js +5 -3
  69. package/dist/users/home-layout/shared.js.map +1 -1
  70. package/package.json +2 -2
@@ -0,0 +1,2 @@
1
+ export * from './request';
2
+ export * from './response';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./request"), exports);
18
+ __exportStar(require("./response"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/semantic-queries/post/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAyB;AACzB,6CAA0B"}
@@ -0,0 +1,36 @@
1
+ import { SemanticQuery, SemanticQueryEntityType, SemanticQueryKind, SemanticOperationPayload } from '../shared';
2
+ /**
3
+ * Register a semantic query — the ONLY way a query enters the system. Reads
4
+ * execute by reference (`semanticQueryId`), never by inline query JSON, so
5
+ * nothing can run without having been validated here first.
6
+ *
7
+ * Registration is not persistence: a new record is a DRAFT with a sliding
8
+ * ~24 h expiry, so the client may register freely on every filter interaction
9
+ * without accumulating garbage. Saving is a separate, later act (PATCH sets a
10
+ * name — the same record is promoted in place and its id never changes).
11
+ */
12
+ export interface PostSemanticQueryRequest {
13
+ entityType: SemanticQueryEntityType;
14
+ semanticQuery: SemanticQuery;
15
+ /** Defaults to `query`. `operation` records also carry `operation`. */
16
+ kind?: SemanticQueryKind;
17
+ /** Required when kind is `operation`; forbidden otherwise. */
18
+ operation?: SemanticOperationPayload;
19
+ /** Human-readable restatement of the query, shown in the UI. */
20
+ description?: string;
21
+ /** The natural-language prompt this query was generated from, as provenance. */
22
+ prompt?: string;
23
+ /**
24
+ * Id of the record this one refines. The chain of `derivedFrom` links is the
25
+ * conversation state for query building — refinement passes the current
26
+ * record id, never a transcript, and undo walks the chain with no AI call.
27
+ */
28
+ derivedFrom?: string;
29
+ /**
30
+ * IANA timezone the query's relative dates resolve against, recorded from
31
+ * registration so a draft means the same thing on every execution — without
32
+ * it, "today" depends on whichever caller runs it (and a widget with no
33
+ * timezone parameter would silently resolve in UTC).
34
+ */
35
+ timezone?: string;
36
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/semantic-queries/post/request.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export { GetSemanticQueryResponse as PostSemanticQueryResponse } from '../get/response';
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.js","sourceRoot":"","sources":["../../../src/semantic-queries/post/response.ts"],"names":[],"mappings":""}
@@ -0,0 +1,356 @@
1
+ import { SortOrders } from '../shared';
2
+ import { AssetSortField } from '../assets/get/query';
3
+ import { LocationStatus } from '../locations/constants';
4
+ import { FieldDataType } from '../fields/constants';
5
+ /**
6
+ * SEMANTIC QUERIES — the portable query language.
7
+ *
8
+ * A semantic query is a JSON list of typed conditions (ANDed together, nestable
9
+ * with and/or groups) over one entity type. Three parties speak this contract —
10
+ * the client filter UI that builds conditions, the LLM that generates them, and
11
+ * the server compiler that executes them — so this file is the single
12
+ * vocabulary all three encode.
13
+ *
14
+ * THE CLOSED-VOCABULARY RULE. Condition types, operators AND property names are
15
+ * closed sets: validation rejects an unknown property rather than ignoring it,
16
+ * at every level. This is not defensive tidiness — an LLM once invented a
17
+ * `"negate": true` property; ignoring it compiled NOT(X) as X, a query that ran
18
+ * successfully and returned exactly the complement of what was asked. Every
19
+ * defect class this design guards against fails SILENTLY (valid query, wrong
20
+ * rows), which is why an honest rejection always beats a plausible guess.
21
+ *
22
+ * There is deliberately NO general negation (no `not` group, no invertible
23
+ * flag). Expressible negatively: `notExists`, `ne`, `geolocation.exists:false`,
24
+ * `kit.isMember:false`. Anything else must surface as a validation issue,
25
+ * never an approximation.
26
+ *
27
+ * Descends from the G2G Chat prototype (see g2g-client
28
+ * `docs/semantic-query-decisions.md` while it lives, folding into
29
+ * TECHNICAL_DECISIONS.md) and the semantic-query specification errata.
30
+ */
31
+ /**
32
+ * What a semantic query targets. Only `asset` executes today; recorded on
33
+ * every stored query from day one so saved records never need retrofitting.
34
+ */
35
+ export declare const semanticQueryEntityTypes: readonly ["asset", "location", "event", "reader", "snapshot", "manifest"];
36
+ export declare type SemanticQueryEntityType = (typeof semanticQueryEntityTypes)[number];
37
+ /**
38
+ * What a stored record IS, as opposed to what it targets.
39
+ * - `query` — a selector. Executing it returns rows.
40
+ * - `operation` — a selector PLUS verbs ("move everything matching this to
41
+ * Southport"). Only the DEFINITION is stored; execution belongs
42
+ * to the bulk-operations API when it exists.
43
+ */
44
+ export declare const semanticQueryKinds: readonly ["query", "operation"];
45
+ export declare type SemanticQueryKind = (typeof semanticQueryKinds)[number];
46
+ export declare const semanticQueryVisibilities: readonly ["private", "organisation"];
47
+ export declare type SemanticQueryVisibility = (typeof semanticQueryVisibilities)[number];
48
+ export declare const semanticRelativeDateBases: readonly ["day", "week", "month", "quarter", "year"];
49
+ export declare type SemanticRelativeDateBase = (typeof semanticRelativeDateBases)[number];
50
+ export declare const semanticRelativeDatePositions: readonly ["start", "end", "same"];
51
+ export declare type SemanticRelativeDatePosition = (typeof semanticRelativeDatePositions)[number];
52
+ /**
53
+ * A relative date, stored UNRESOLVED — that is the point. A saved query whose
54
+ * date resolved at save time silently means the wrong period forever; leaving
55
+ * it symbolic means "last 30 days" re-run next month means next month.
56
+ * Resolution happens at execution, against an explicit timezone.
57
+ *
58
+ * `offset`: 0 = this period, 1 = next, -1 = last, -30 = thirty periods ago.
59
+ *
60
+ * `position`:
61
+ * - `start` / `end` snap to the boundaries of the named period (calendar
62
+ * semantics — "start of last month").
63
+ * - `same` is the same day-of-month, `offset` periods away, clamped for short
64
+ * months (31 Jan + 1 month = 28/29 Feb). Without it "one month from today"
65
+ * is inexpressible — `{base:'month', offset:1, position:'start'}` is the 1st
66
+ * of next month and `{base:'day', offset:30}` drifts. Service and inspection
67
+ * intervals are quoted in months, so for date-setting operations `same` is
68
+ * the common case, not an edge case. Meaningless for `day` (the offset is
69
+ * already in days).
70
+ *
71
+ * Sibling of the platform's `DateCondition`/`DateOffset` (shared/relative-date
72
+ * .ts), which derives period boundaries from the comparison operator instead.
73
+ * This shape exists separately because it is what the LLM emits and what
74
+ * stored queries carry, and because `position: 'same'` has no `DateCondition`
75
+ * encoding. One resolver serves both (assets resolve-date).
76
+ */
77
+ export interface SemanticRelativeDate {
78
+ relative: true;
79
+ base: SemanticRelativeDateBase;
80
+ offset: number;
81
+ /** Required for week/month/quarter/year; optional for day. */
82
+ position?: SemanticRelativeDatePosition;
83
+ }
84
+ /** An absolute `"YYYY-MM-DD"` date, or a relative one. A range is always two conditions (gte + lt). */
85
+ export declare type SemanticDateValue = string | SemanticRelativeDate;
86
+ export declare const semanticFieldOperators: readonly ["eq", "ne", "gt", "gte", "lt", "lte", "contains", "exists", "notExists"];
87
+ export declare type SemanticFieldOperator = (typeof semanticFieldOperators)[number];
88
+ export declare const semanticTimestampOperators: readonly ["gt", "gte", "lt", "lte"];
89
+ export declare type SemanticTimestampOperator = (typeof semanticTimestampOperators)[number];
90
+ export declare const semanticComparisonOperators: readonly ["eq", "ne", "gt", "gte", "lt", "lte"];
91
+ export declare type SemanticComparisonOperator = (typeof semanticComparisonOperators)[number];
92
+ export declare const semanticSetOperators: readonly ["any", "all"];
93
+ export declare type SemanticSetOperator = (typeof semanticSetOperators)[number];
94
+ /**
95
+ * Grouping. Two interfaces rather than one with `type: 'and' | 'or'` so that
96
+ * `Extract<SemanticQueryCondition, { type: 'or' }>` narrows — with a shared
97
+ * interface it collapses to `never`.
98
+ */
99
+ export interface SemanticAndCondition {
100
+ type: 'and';
101
+ conditions: SemanticQueryCondition[];
102
+ }
103
+ export interface SemanticOrCondition {
104
+ type: 'or';
105
+ conditions: SemanticQueryCondition[];
106
+ }
107
+ /** Matches a type subtree by pipe-delimited path ("Vehicle|Forklift|"). */
108
+ export interface SemanticAssetTypeCondition {
109
+ type: 'assetType';
110
+ path: string;
111
+ /** Default true — the type and everything under it. False = exact type only. */
112
+ includeSubtypes?: boolean;
113
+ }
114
+ /**
115
+ * Matches a location subtree by pipe-delimited path. `location` is where the
116
+ * asset currently IS; `homeLocation` is where it BELONGS — a fixed, often
117
+ * high-level node. Conflating them fails silently, so they are distinct types.
118
+ */
119
+ export interface SemanticLocationCondition {
120
+ type: 'location' | 'homeLocation';
121
+ path: string;
122
+ /** Default true. */
123
+ includeSublocations?: boolean;
124
+ }
125
+ /**
126
+ * Assets currently travelling with another asset — the defibrillator in the
127
+ * ambulance. (The carrier side — "can hold other assets" — is deliberately not
128
+ * in the language: ruled out 2026-07-31.)
129
+ *
130
+ * NOTE the producer gap (prototype finding #12): nothing can currently supply
131
+ * an `assetId` — the AI is never asked for an id (models invent them, and a
132
+ * fabricated id runs and matches nothing) and the client UI has no
133
+ * asset-picking filter. PARKED by ruling (Aaron, 2026-08-03): a peer solution
134
+ * is incoming; until then the AI declines "what's in <asset>" honestly and
135
+ * only `hasAny` is produced.
136
+ */
137
+ export interface SemanticWithAssetCondition {
138
+ type: 'withAsset';
139
+ /** With one specific asset. */
140
+ assetId?: string;
141
+ /** With any asset at all (or none, when false). */
142
+ hasAny?: boolean;
143
+ }
144
+ /**
145
+ * A custom-field condition.
146
+ *
147
+ * `ne` INCLUDES UNSET by default: "Ownership ≠ QH" counts assets where the
148
+ * field is absent, because that is how the English reads. On a sparse field
149
+ * the two readings differ by orders of magnitude (2 rows vs 785 measured).
150
+ * `includeUnset: false` opts into the strict has-the-field-and-differs
151
+ * reading.
152
+ *
153
+ * Fields whose values live on the asset TYPE (inherited down the type
154
+ * hierarchy) are the compiler's problem, not the caller's: the condition shape
155
+ * is identical and the compiler resolves type-level values itself. Without
156
+ * that, the flagship "assets by Manufacturer" query matches nothing.
157
+ */
158
+ export interface SemanticCustomFieldCondition {
159
+ type: 'customField';
160
+ fieldName: string;
161
+ /** Advisory only — the authoritative dataType comes from the field catalogue. */
162
+ dataType?: FieldDataType;
163
+ operator: SemanticFieldOperator;
164
+ value?: string | number | boolean | SemanticRelativeDate;
165
+ /** For `ne` only. Default true. */
166
+ includeUnset?: boolean;
167
+ }
168
+ /**
169
+ * The timestamp family:
170
+ * - `createdDate` — when the asset was created
171
+ * - `lastUpdated` — the asset's own record edited through the APIs
172
+ * - `lastChanged` — ANY system touched the asset, including location /
173
+ * telemetry updates (drives offline-sync deltas)
174
+ * - `lastSeen` / `firstSeen` — detection timestamps
175
+ *
176
+ * "Edited / record changed" wording maps to `lastUpdated`; "moved / touched /
177
+ * anything happened" maps to `lastChanged` — genuinely different questions
178
+ * with substantially different answers.
179
+ *
180
+ * `lt`/`lte` INCLUDE NEVER-SET by default: none of these fields exist on an
181
+ * asset that has never been modified/seen, so a naive "not updated since
182
+ * March" excludes exactly the assets the user is usually looking for.
183
+ * `includeNeverSet: false` opts out.
184
+ *
185
+ * Comparison operators only — bare timestamp existence was ruled out of the
186
+ * language (gap #6, 2026-07-31); "never seen" is `locationStatus: NEVERSEEN`.
187
+ */
188
+ export interface SemanticTimestampCondition {
189
+ type: 'createdDate' | 'lastUpdated' | 'lastChanged' | 'lastSeen' | 'firstSeen';
190
+ operator: SemanticTimestampOperator;
191
+ /** Required for comparisons; forbidden for exists/notExists. */
192
+ value?: SemanticDateValue;
193
+ /** For `lt`/`lte` only. Default true. */
194
+ includeNeverSet?: boolean;
195
+ }
196
+ /** Whether the asset has map coordinates. Nothing more — "online" is not a concept assets have. */
197
+ export interface SemanticGeolocationCondition {
198
+ type: 'geolocation';
199
+ exists: boolean;
200
+ }
201
+ /** Tag conditions take tag IDS, not display names. `any` (default) or `all`. */
202
+ export interface SemanticTagsCondition {
203
+ type: 'tags';
204
+ operator?: SemanticSetOperator;
205
+ values: string[];
206
+ }
207
+ export declare const semanticTelemetryFields: readonly ["battery", "temperature", "voltage"];
208
+ export declare type SemanticTelemetryField = (typeof semanticTelemetryFields)[number];
209
+ export interface SemanticTelemetryCondition {
210
+ type: 'telemetry';
211
+ field: SemanticTelemetryField;
212
+ operator: SemanticComparisonOperator;
213
+ value: number;
214
+ }
215
+ /** Readiness severity scale (contract shared/readiness.ts): 0 green, 1 amber, 2 red. */
216
+ export declare const semanticReadinessLevels: readonly [0, 1, 2];
217
+ export declare type SemanticReadinessLevel = (typeof semanticReadinessLevels)[number];
218
+ /**
219
+ * Readiness. Missing `readiness` on an asset means green — a query including
220
+ * level 0 must also match never-evaluated assets (the compiler owns that).
221
+ * `level` and `levels` are mutually exclusive.
222
+ */
223
+ export interface SemanticReadinessCondition {
224
+ type: 'readiness';
225
+ level?: SemanticReadinessLevel;
226
+ /** Any of several levels — e.g. [1, 2] for "not fully ready". */
227
+ levels?: SemanticReadinessLevel[];
228
+ }
229
+ /**
230
+ * Kits / grouping. Exactly one property may be set. The negative forms match
231
+ * assets where the flag is absent as well as false (the flags are stored
232
+ * true-or-absent).
233
+ *
234
+ * `parentAssetId` shares the withAsset producer gap above — parked the same
235
+ * way; the AI declines "members of kit <name>" until the incoming solution.
236
+ */
237
+ export interface SemanticKitCondition {
238
+ type: 'kit';
239
+ /** The asset is itself a kit. */
240
+ isKit?: boolean;
241
+ /** The asset belongs to a kit. */
242
+ isMember?: boolean;
243
+ /** The kit's membership requirements are met. */
244
+ satisfied?: boolean;
245
+ /** Members of one specific kit. */
246
+ parentAssetId?: string;
247
+ }
248
+ /**
249
+ * Location status ("currently dispatched", "never seen", …). `NEVERSEEN`
250
+ * matches assets with no state at all as well as the explicit status — the
251
+ * compiler owns that missing-state semantic.
252
+ */
253
+ export interface SemanticLocationStatusCondition {
254
+ type: 'locationStatus';
255
+ values: LocationStatus[];
256
+ }
257
+ /**
258
+ * The complete condition vocabulary, as data.
259
+ *
260
+ * Exported from the contract so the compiler's property whitelist and the
261
+ * boundary schema are both keyed off ONE list: a condition type added here is
262
+ * a compile error in any layer that has not handled it, instead of a silently
263
+ * unchecked type (a missing whitelist entry means "no properties checked",
264
+ * which is precisely the failure the closed vocabulary exists to prevent).
265
+ */
266
+ export declare const semanticConditionTypes: readonly ["and", "or", "assetType", "location", "homeLocation", "withAsset", "customField", "createdDate", "lastUpdated", "lastChanged", "lastSeen", "firstSeen", "geolocation", "tags", "telemetry", "readiness", "kit", "locationStatus"];
267
+ export declare type SemanticConditionType = (typeof semanticConditionTypes)[number];
268
+ /**
269
+ * Query size bounds, shared by the boundary schema (which refuses an oversized
270
+ * query before parsing it) and the compiler (which counts every branch as it
271
+ * walks). Both halves are load-bearing: without the compiler's counting a
272
+ * single `or` could carry thousands of arms, and without the boundary's cap
273
+ * the parse itself is the cost.
274
+ */
275
+ export declare const SEMANTIC_QUERY_LIMITS: {
276
+ readonly maxConditions: 50;
277
+ readonly maxDepth: 5;
278
+ };
279
+ export declare type SemanticQueryCondition = SemanticAndCondition | SemanticOrCondition | SemanticAssetTypeCondition | SemanticLocationCondition | SemanticWithAssetCondition | SemanticCustomFieldCondition | SemanticTimestampCondition | SemanticGeolocationCondition | SemanticTagsCondition | SemanticTelemetryCondition | SemanticReadinessCondition | SemanticKitCondition | SemanticLocationStatusCondition;
280
+ /** Current wire version of the condition vocabulary. */
281
+ export declare const SEMANTIC_QUERY_VERSION = 2;
282
+ export interface SemanticQuery {
283
+ /** Defaults to the current version when absent. */
284
+ version?: number;
285
+ /** ANDed together. Empty is valid — "everything" (entity defaults may bound it). */
286
+ conditions: SemanticQueryCondition[];
287
+ }
288
+ /**
289
+ * PATHS MATCH, IDS POINT. A hierarchical path is for MATCHING a subtree; an id
290
+ * is for pointing at ONE specific record. Setting an asset's location is
291
+ * unambiguous by definition, so it always takes `locationId` — `locationPath`
292
+ * rides along only as a display label. Field names are unique, so `fieldName`
293
+ * needs no resolution step.
294
+ */
295
+ export declare type SemanticAssetOperation =
296
+ /**
297
+ * A DATE field's value may be a SemanticRelativeDate, left UNRESOLVED
298
+ * exactly as in a query — otherwise "set expiry to 12 months from today"
299
+ * freezes the date it was authored on, and re-running it next year is wrong.
300
+ */
301
+ {
302
+ op: 'setField';
303
+ fieldName: string;
304
+ value: string | number | boolean | SemanticRelativeDate;
305
+ } | {
306
+ op: 'clearField';
307
+ fieldName: string;
308
+ } | {
309
+ op: 'setLocation';
310
+ locationId: string;
311
+ locationPath?: string;
312
+ }
313
+ /** Where the asset BELONGS — a different property from where it IS. */
314
+ | {
315
+ op: 'setHomeLocation';
316
+ locationId: string;
317
+ locationPath?: string;
318
+ }
319
+ /**
320
+ * Stored but NOT executable, and deliberately not translated to a sentinel
321
+ * id: asset location state has many permutations (current, home,
322
+ * with-another-asset, pending dispatch), so "clear the location" is not one
323
+ * well-defined write. Captured so the intent is not lost; a no-op until the
324
+ * semantics are decided.
325
+ */
326
+ | {
327
+ op: 'clearLocation';
328
+ }
329
+ /**
330
+ * Captured but PENDING: clearing a home location means setting it to the
331
+ * organisation's root location. Whether that is expressed as the root id or
332
+ * resolved server-side is an open question with the API team — this op
333
+ * deliberately carries no id until settled.
334
+ */
335
+ | {
336
+ op: 'clearHomeLocation';
337
+ }
338
+ /** Irreversible — requires explicit confirmation at execution time. */
339
+ | {
340
+ op: 'delete';
341
+ };
342
+ export interface SemanticOperationPayload {
343
+ operations: SemanticAssetOperation[];
344
+ /** Human-readable restatement, shown on the confirmation card. */
345
+ description: string;
346
+ }
347
+ /**
348
+ * How a saved query's list displays — columns and sort. Populated on
349
+ * promotion (save); absent on drafts.
350
+ */
351
+ export interface SemanticQueryDisplay {
352
+ columnVisibility?: Record<string, boolean>;
353
+ columnOrder?: string[];
354
+ sort?: AssetSortField;
355
+ sortOrder?: SortOrders;
356
+ }
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SEMANTIC_QUERY_VERSION = exports.SEMANTIC_QUERY_LIMITS = exports.semanticConditionTypes = exports.semanticReadinessLevels = exports.semanticTelemetryFields = exports.semanticSetOperators = exports.semanticComparisonOperators = exports.semanticTimestampOperators = exports.semanticFieldOperators = exports.semanticRelativeDatePositions = exports.semanticRelativeDateBases = exports.semanticQueryVisibilities = exports.semanticQueryKinds = exports.semanticQueryEntityTypes = void 0;
4
+ /**
5
+ * SEMANTIC QUERIES — the portable query language.
6
+ *
7
+ * A semantic query is a JSON list of typed conditions (ANDed together, nestable
8
+ * with and/or groups) over one entity type. Three parties speak this contract —
9
+ * the client filter UI that builds conditions, the LLM that generates them, and
10
+ * the server compiler that executes them — so this file is the single
11
+ * vocabulary all three encode.
12
+ *
13
+ * THE CLOSED-VOCABULARY RULE. Condition types, operators AND property names are
14
+ * closed sets: validation rejects an unknown property rather than ignoring it,
15
+ * at every level. This is not defensive tidiness — an LLM once invented a
16
+ * `"negate": true` property; ignoring it compiled NOT(X) as X, a query that ran
17
+ * successfully and returned exactly the complement of what was asked. Every
18
+ * defect class this design guards against fails SILENTLY (valid query, wrong
19
+ * rows), which is why an honest rejection always beats a plausible guess.
20
+ *
21
+ * There is deliberately NO general negation (no `not` group, no invertible
22
+ * flag). Expressible negatively: `notExists`, `ne`, `geolocation.exists:false`,
23
+ * `kit.isMember:false`. Anything else must surface as a validation issue,
24
+ * never an approximation.
25
+ *
26
+ * Descends from the G2G Chat prototype (see g2g-client
27
+ * `docs/semantic-query-decisions.md` while it lives, folding into
28
+ * TECHNICAL_DECISIONS.md) and the semantic-query specification errata.
29
+ */
30
+ // --- Entity + record kind -------------------------------------------------
31
+ /**
32
+ * What a semantic query targets. Only `asset` executes today; recorded on
33
+ * every stored query from day one so saved records never need retrofitting.
34
+ */
35
+ exports.semanticQueryEntityTypes = [
36
+ 'asset',
37
+ 'location',
38
+ 'event',
39
+ 'reader',
40
+ 'snapshot',
41
+ 'manifest',
42
+ ];
43
+ /**
44
+ * What a stored record IS, as opposed to what it targets.
45
+ * - `query` — a selector. Executing it returns rows.
46
+ * - `operation` — a selector PLUS verbs ("move everything matching this to
47
+ * Southport"). Only the DEFINITION is stored; execution belongs
48
+ * to the bulk-operations API when it exists.
49
+ */
50
+ exports.semanticQueryKinds = ['query', 'operation'];
51
+ exports.semanticQueryVisibilities = ['private', 'organisation'];
52
+ // --- Relative dates -------------------------------------------------------
53
+ exports.semanticRelativeDateBases = [
54
+ 'day',
55
+ 'week',
56
+ 'month',
57
+ 'quarter',
58
+ 'year',
59
+ ];
60
+ exports.semanticRelativeDatePositions = ['start', 'end', 'same'];
61
+ // --- Operators ------------------------------------------------------------
62
+ exports.semanticFieldOperators = [
63
+ 'eq',
64
+ 'ne',
65
+ 'gt',
66
+ 'gte',
67
+ 'lt',
68
+ 'lte',
69
+ 'contains',
70
+ 'exists',
71
+ 'notExists',
72
+ ];
73
+ exports.semanticTimestampOperators = ['gt', 'gte', 'lt', 'lte'];
74
+ exports.semanticComparisonOperators = [
75
+ 'eq',
76
+ 'ne',
77
+ 'gt',
78
+ 'gte',
79
+ 'lt',
80
+ 'lte',
81
+ ];
82
+ exports.semanticSetOperators = ['any', 'all'];
83
+ exports.semanticTelemetryFields = [
84
+ 'battery',
85
+ 'temperature',
86
+ 'voltage',
87
+ ];
88
+ /** Readiness severity scale (contract shared/readiness.ts): 0 green, 1 amber, 2 red. */
89
+ exports.semanticReadinessLevels = [0, 1, 2];
90
+ /**
91
+ * The complete condition vocabulary, as data.
92
+ *
93
+ * Exported from the contract so the compiler's property whitelist and the
94
+ * boundary schema are both keyed off ONE list: a condition type added here is
95
+ * a compile error in any layer that has not handled it, instead of a silently
96
+ * unchecked type (a missing whitelist entry means "no properties checked",
97
+ * which is precisely the failure the closed vocabulary exists to prevent).
98
+ */
99
+ exports.semanticConditionTypes = [
100
+ 'and',
101
+ 'or',
102
+ 'assetType',
103
+ 'location',
104
+ 'homeLocation',
105
+ 'withAsset',
106
+ 'customField',
107
+ 'createdDate',
108
+ 'lastUpdated',
109
+ 'lastChanged',
110
+ 'lastSeen',
111
+ 'firstSeen',
112
+ 'geolocation',
113
+ 'tags',
114
+ 'telemetry',
115
+ 'readiness',
116
+ 'kit',
117
+ 'locationStatus',
118
+ ];
119
+ /**
120
+ * Query size bounds, shared by the boundary schema (which refuses an oversized
121
+ * query before parsing it) and the compiler (which counts every branch as it
122
+ * walks). Both halves are load-bearing: without the compiler's counting a
123
+ * single `or` could carry thousands of arms, and without the boundary's cap
124
+ * the parse itself is the cost.
125
+ */
126
+ exports.SEMANTIC_QUERY_LIMITS = {
127
+ maxConditions: 50,
128
+ maxDepth: 5,
129
+ };
130
+ // --- The envelope ---------------------------------------------------------
131
+ /** Current wire version of the condition vocabulary. */
132
+ exports.SEMANTIC_QUERY_VERSION = 2;
133
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/semantic-queries/shared.ts"],"names":[],"mappings":";;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,6EAA6E;AAE7E;;;GAGG;AACU,QAAA,wBAAwB,GAAG;IACtC,OAAO;IACP,UAAU;IACV,OAAO;IACP,QAAQ;IACR,UAAU;IACV,UAAU;CACF,CAAA;AAGV;;;;;;GAMG;AACU,QAAA,kBAAkB,GAAG,CAAC,OAAO,EAAE,WAAW,CAAU,CAAA;AAGpD,QAAA,yBAAyB,GAAG,CAAC,SAAS,EAAE,cAAc,CAAU,CAAA;AAG7E,6EAA6E;AAEhE,QAAA,yBAAyB,GAAG;IACvC,KAAK;IACL,MAAM;IACN,OAAO;IACP,SAAS;IACT,MAAM;CACE,CAAA;AAGG,QAAA,6BAA6B,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAU,CAAA;AAwC9E,6EAA6E;AAEhE,QAAA,sBAAsB,GAAG;IACpC,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,KAAK;IACL,UAAU;IACV,QAAQ;IACR,WAAW;CACH,CAAA;AAGG,QAAA,0BAA0B,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAU,CAAA;AAIhE,QAAA,2BAA2B,GAAG;IACzC,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,KAAK;CACG,CAAA;AAIG,QAAA,oBAAoB,GAAG,CAAC,KAAK,EAAE,KAAK,CAAU,CAAA;AA+H9C,QAAA,uBAAuB,GAAG;IACrC,SAAS;IACT,aAAa;IACb,SAAS;CACD,CAAA;AAUV,wFAAwF;AAC3E,QAAA,uBAAuB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAU,CAAA;AA6CzD;;;;;;;;GAQG;AACU,QAAA,sBAAsB,GAAG;IACpC,KAAK;IACL,IAAI;IACJ,WAAW;IACX,UAAU;IACV,cAAc;IACd,WAAW;IACX,aAAa;IACb,aAAa;IACb,aAAa;IACb,aAAa;IACb,UAAU;IACV,WAAW;IACX,aAAa;IACb,MAAM;IACN,WAAW;IACX,WAAW;IACX,KAAK;IACL,gBAAgB;CACR,CAAA;AAGV;;;;;;GAMG;AACU,QAAA,qBAAqB,GAAG;IACnC,aAAa,EAAE,EAAE;IACjB,QAAQ,EAAE,CAAC;CACH,CAAA;AAiBV,6EAA6E;AAE7E,wDAAwD;AAC3C,QAAA,sBAAsB,GAAG,CAAC,CAAA"}
@@ -7,9 +7,11 @@
7
7
  * A layout is a flat, ordered list of widgets, each pinned to a rect on a
8
8
  * 4-column grid (`gridPos`). The widget `type` is a closed union (below): adding
9
9
  * a new kind is a contract change + republish + client bump. Per-widget `config`
10
- * is left opaque and carries widget *behaviour* only (a saved-view id, an action
11
- * id, a heading's text) — never geometry — so a widget can evolve without a
12
- * contract change while the API still validates the structural parts.
10
+ * carries widget *behaviour* only (a saved-view id, an action id, a heading's
11
+ * text) — never geometry. Since 2026-07-30 the API validates each kind's KNOWN
12
+ * config keys on write (the per-kind `*WidgetConfig` shapes below) while
13
+ * tolerating unknown keys, so the client can still add config keys without an
14
+ * API deploy ordering — only changing a known key's meaning needs one.
13
15
  *
14
16
  * `version` discriminates stored layouts so the client can detect and
15
17
  * reset/migrate an older one on read.
@@ -30,6 +32,38 @@
30
32
  * expressed through `gridPos.w`, not enforced by the API.
31
33
  */
32
34
  export declare type HomeWidgetType = 'tile-link' | 'summary-list' | 'recent-activity' | 'recent-assets' | 'recent-locations' | 'needs-attention' | 'kit-spotlight' | 'hero' | 'heading';
35
+ /**
36
+ * Per-kind `config` shapes — the authoritative form of each configurable
37
+ * kind's KNOWN keys, which the API enforces on write (unknown keys pass, so
38
+ * these can grow client-first). The feed kinds define no config keys. `config`
39
+ * itself stays loosely typed on `HomeWidget`; the client parses defensively at
40
+ * the render boundary regardless (stored data may predate validation).
41
+ */
42
+ /** A `tile-link`'s target: a registered app action or a saved view — never a
43
+ * free URL (the client resolves targets to internal routes by design). */
44
+ export declare type TileLinkWidgetConfig = {
45
+ source: 'action';
46
+ actionId: string;
47
+ } | {
48
+ source: 'view';
49
+ viewId: string;
50
+ };
51
+ /** A `summary-list` renders the top matches of one saved view. */
52
+ export interface SummaryListWidgetConfig {
53
+ viewId: string;
54
+ }
55
+ /** A `heading`'s user-editable label — empty while freshly added. */
56
+ export interface HeadingWidgetConfig {
57
+ text: string;
58
+ }
59
+ /** The `hero`'s data source: the whole account's assets, or one saved view's
60
+ * matches. Always present on a stored hero (the kind shipped with it). */
61
+ export declare type HeroWidgetConfig = {
62
+ source: 'account';
63
+ } | {
64
+ source: 'view';
65
+ viewId: string;
66
+ };
33
67
  /**
34
68
  * A widget's cell on the Home grid: top-left position (`x`/`y`) and size
35
69
  * (`w`/`h`), in grid units. The grid is 4 columns wide, so `x + w <= 4`, and
@@ -53,7 +87,7 @@ export interface HomeWidget {
53
87
  type: HomeWidgetType;
54
88
  /** Position + size on the 4-column grid. */
55
89
  gridPos: HomeWidgetGridPos;
56
- /** Widget-specific *behaviour* config (e.g. a saved-view id, a heading's text). Opaque to the API; never geometry. */
90
+ /** Widget-specific *behaviour* config (e.g. a saved-view id, a heading's text) — never geometry. Known keys are validated per kind (see the `*WidgetConfig` shapes); unknown keys pass through. */
57
91
  config?: Record<string, unknown>;
58
92
  }
59
93
  export interface HomeLayout {
@@ -8,9 +8,11 @@
8
8
  * A layout is a flat, ordered list of widgets, each pinned to a rect on a
9
9
  * 4-column grid (`gridPos`). The widget `type` is a closed union (below): adding
10
10
  * a new kind is a contract change + republish + client bump. Per-widget `config`
11
- * is left opaque and carries widget *behaviour* only (a saved-view id, an action
12
- * id, a heading's text) — never geometry — so a widget can evolve without a
13
- * contract change while the API still validates the structural parts.
11
+ * carries widget *behaviour* only (a saved-view id, an action id, a heading's
12
+ * text) — never geometry. Since 2026-07-30 the API validates each kind's KNOWN
13
+ * config keys on write (the per-kind `*WidgetConfig` shapes below) while
14
+ * tolerating unknown keys, so the client can still add config keys without an
15
+ * API deploy ordering — only changing a known key's meaning needs one.
14
16
  *
15
17
  * `version` discriminates stored layouts so the client can detect and
16
18
  * reset/migrate an older one on read.
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/users/home-layout/shared.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG"}
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/users/home-layout/shared.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG"}