sil-openclaw 0.3.8 → 0.4.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.
@@ -36,23 +36,22 @@
36
36
  *
37
37
  * GET <silApiUrl>/identity Authorization: Bearer <access_token>
38
38
  * (no body, no content-type)
39
- * 200 <UCP envelope>{ result: { name, addresses } } → ok (carries identity)
39
+ * 200 { name, addresses } → ok (carries identity)
40
40
  * 401 → unauthorized (→ refresh)
41
41
  * 403 { error: user_not_provisioned | principal_mismatch } → forbidden (terminal)
42
42
  * 5xx / network / abort → retryable
43
43
  *
44
44
  * Wire contract for the sil-API catalog search (SAME origin as the identity
45
45
  * read — sil-api, bare path, NOT /api/v1; see the sil-search card). A simplified
46
- * structured query in, ranked purchasable products out. sil-api owns the UCP
47
- * envelope + enrichment; the plugin sends NO envelope and fills NO defaults:
46
+ * structured query in, ranked purchasable products out. sil-api owns the
47
+ * enrichment; the plugin sends NO envelope and fills NO defaults:
48
48
  *
49
49
  * POST <silApiUrl>/catalog/search Authorization: Bearer <access_token>
50
50
  * body { query?, filters?:{ categories?, price?:{ min?, max? } },
51
51
  * pagination?:{ cursor?, limit? } } (no context, no envelope)
52
- * 200 <FLAT UCP envelope>{ ucp, products: SilCatalogProduct[],
53
- * pagination?:{ has_next_page, cursor? } } → ok
54
- * (sil-api's `withUcpMeta(body) → { ucp, ...body }`: `products`/`pagination`
55
- * at the TOP LEVEL beside `ucp`, NO `result` wrapper)
52
+ * 200 { products: SilCatalogProduct[],
53
+ * pagination?:{ has_next_page, cursor? } } → ok
54
+ * (`products`/`pagination` at the TOP LEVEL, NO `result` wrapper)
56
55
  * 400 { error:"empty_search_input", message } → invalid_request
57
56
  * 401 → unauthorized (→ refresh)
58
57
  * 5xx / network / abort → retryable
@@ -61,16 +60,15 @@
61
60
  * sil-api, bare `/catalog/lookup`, NOT /api/v1; see the sil-product-get card). The
62
61
  * lookup COMPANION to search: an agent passes ids it already holds and gets fresh
63
62
  * RICH detail back (search is LEAN). sil-api owns enrichment + the `not_found`
64
- * messaging + the envelope; the plugin sends just `{ ids }` (NO filters/context,
63
+ * messaging; the plugin sends just `{ ids }` (NO filters/context,
65
64
  * NO envelope). The two structural deltas from search's response: NO `pagination`
66
65
  * (a batch resolve, not a list) and a `messages[]` carrying the misses:
67
66
  *
68
67
  * POST <silApiUrl>/catalog/lookup Authorization: Bearer <access_token>
69
68
  * body { ids: string[] } (≥1; no filters/context)
70
- * 200 <FLAT UCP envelope>{ ucp, products: SilCatalogProduct[],
71
- * messages?:[{ type:"info", code:"not_found", content:<id> }] } → ok
72
- * (same flat `withUcpMeta` shape: `products`/`messages` at the TOP LEVEL
73
- * beside `ucp`, NO `result` wrapper)
69
+ * 200 { products: SilCatalogProduct[],
70
+ * messages?:[{ type:"info", code:"not_found", content:<id> }] } → ok
71
+ * (`products`/`messages` at the TOP LEVEL, NO `result` wrapper)
74
72
  * 400 (schema: empty `ids` / request_too_large) → invalid_request
75
73
  * 401 → unauthorized (→ refresh)
76
74
  * 5xx / network / abort → retryable
@@ -88,6 +86,32 @@
88
86
  * `not_found` → `ok` (success: "none of these exist anymore"), the discriminator
89
87
  * being array PRESENCE, never length.
90
88
  *
89
+ * Wire contract for the sil-API spec REGISTRY (SAME origin/path style as search —
90
+ * sil-api, bare `/catalog/specs`, NOT /api/v1; see the sds-specs-client-tool card).
91
+ * The dedupe-or-create up-flow: at method mint/refresh the method submits its coined
92
+ * spec DEFINITIONS and gets back the canonical `ns.key` to adopt (born canonical,
93
+ * BEFORE persist). sil-api owns the dedupe authority; the plugin sends `{ query,
94
+ * specs }` (NO envelope) and reads the resolutions straight off the body:
95
+ *
96
+ * POST <silApiUrl>/catalog/specs Authorization: Bearer <access_token>
97
+ * body { query, specs: SpecDefinition[] } (both required; specs ≥1)
98
+ * 200 { resolved: SpecResolution[] } → ok
99
+ * (BARE `{ resolved }` at the TOP LEVEL — NO `ucp` meta, NO `result`
100
+ * wrapper; specs is an INTERNAL agent↔service op, not a UCP message)
101
+ * 400 (schema: empty specs / blank query) → invalid_request
102
+ * 401 → unauthorized (→ refresh)
103
+ * 403 { error } → forbidden (terminal)
104
+ * 5xx / network / abort → retryable
105
+ *
106
+ * The error arms are a STRICT SUBSET of search's: there is NO 422 SourceError arm
107
+ * and NO `source` attribution — the registry is sil's OWN Postgres, not an external
108
+ * source (handlers/specs.ts), so a specs `retryable` is always BARE. Every
109
+ * well-formed request resolves EVERY submitted spec 1:1 (`matched`|`created`);
110
+ * `classifySpecsResponse` gates `ok` on `Array.isArray(resolved)` AND a NON-EMPTY
111
+ * array of fully-formed resolutions — a partial / garbage / EMPTY-`resolved` 200
112
+ * falls WHOLE to `retryable` (the method can't adopt a canonical name it never got
113
+ * back, and there is NO valid empty-match success here, unlike search's empty list).
114
+ *
91
115
  * `SilCatalogProduct` = a UCP product PLUS a required `source`; each variant PLUS
92
116
  * a required non-empty `checkout_url` (sil-services `@sil/schemas` catalog.ts —
93
117
  * the byte-shape of truth; `@ucp-js/sdk` carries ZERO catalog types). The plugin
@@ -252,11 +276,11 @@ export function classifyIdentityResponse(status, body) {
252
276
  * shared forbidden envelope, never the false-transient `retryable`, and a
253
277
  * valid-but-unprovisioned token gains nothing from a refresh.
254
278
  * 5xx / other non-200 → retryable
255
- * 200 → read `products` off sil-api's FLAT envelope (`{ ucp, products,
256
- * pagination? }` — top level, no `result` wrapper), normalize, and require
279
+ * 200 → read `products` off sil-api's FLAT body (`{ products, pagination? }` —
280
+ * top level, no `result` wrapper), normalize, and require
257
281
  * `products` to be a real ARRAY. A 200 that yields no usable top-level
258
- * products array (a partial / garbage / stub-shaped body, or one carrying
259
- * only `ucp` metadata) is `retryable`, NEVER `ok` — the
282
+ * products array (a partial / garbage / stub-shaped body) is `retryable`,
283
+ * NEVER `ok` — the
260
284
  * `Array.isArray(products)` gate is the anti-false-green guard, the
261
285
  * analogue of the identity `name`-gate. A genuine empty match (200 whose
262
286
  * top-level `products` IS `[]`) is `ok` with an empty product list: a
@@ -313,8 +337,8 @@ export function classifySearchResponse(status, body) {
313
337
  * envelope, never the false-transient `retryable`; it is NOT a 401, so no
314
338
  * refresh is triggered.
315
339
  * 5xx / other non-200 → retryable
316
- * 200 → read `products` off sil-api's FLAT envelope (`{ ucp, products,
317
- * messages? }` — top level, no `result` wrapper), normalize, and require
340
+ * 200 → read `products` off sil-api's FLAT body (`{ products, messages? }` —
341
+ * top level, no `result` wrapper), normalize, and require
318
342
  * `products` to be a real ARRAY. A 200 that yields no usable top-level
319
343
  * products array (a partial / garbage / stub-shaped body) is `retryable`,
320
344
  * NEVER `ok` — the `Array.isArray(products)` gate is the anti-false-green
@@ -357,6 +381,44 @@ export function classifyLookupResponse(status, body) {
357
381
  return { kind: "retryable" };
358
382
  return { kind: "ok", ...result };
359
383
  }
384
+ /**
385
+ * Classify a sil-api spec-REGISTRY response from its HTTP status AND body. A STRICT
386
+ * SUBSET of `classifySearchResponse` — same 400/401/403 arms, but NO 422 arm and a
387
+ * BARE `retryable` (the registry has no external source to attribute):
388
+ * 400 → invalid_request (schema reject: empty `specs` / blank `query` — surface
389
+ * the server's `{ error, message }`; NOT retryable, NOT re-register)
390
+ * 401 → unauthorized (the refresh trigger — the caller drives transparent
391
+ * refresh-and-retry-once via `refreshAndRetryOnce`, parity with search)
392
+ * 403 → forbidden (terminal-but-recoverable; carries the actionable reason
393
+ * `user_not_provisioned`/`principal_mismatch`, defaulting to `"forbidden"`)
394
+ * 5xx / other non-200 → retryable (BARE — no `source`/`detail`; the registry is
395
+ * sil's own Postgres, so there is nothing external to name)
396
+ * 200 → read `resolved` off the FLAT body (`{ resolved }` — top level, NO `ucp`
397
+ * meta, NO `result` wrapper) and require a NON-EMPTY array of fully-formed
398
+ * resolutions via {@link extractSpecsResult}. A 200 with no usable array (a
399
+ * partial / garbage / stub / EMPTY-`resolved` body) is `retryable`, NEVER
400
+ * `ok` — `Array.isArray(resolved)` is the anti-false-green gate. Unlike
401
+ * search there is NO valid empty-match: the server owes a 1:1 resolution, so
402
+ * an empty or short `resolved` is a malformed 200, not a success.
403
+ *
404
+ * Pure and exported — unit-tested in isolation like `classifySearchResponse`.
405
+ */
406
+ export function classifySpecsResponse(status, body) {
407
+ if (status === 400) {
408
+ const { error, message } = extractApiError(body);
409
+ return { kind: "invalid_request", error, message };
410
+ }
411
+ if (status === 401)
412
+ return { kind: "unauthorized" };
413
+ if (status === 403)
414
+ return { kind: "forbidden", reason: extractForbiddenReason(body) };
415
+ if (status !== 200)
416
+ return { kind: "retryable" };
417
+ const resolved = extractSpecsResult(body);
418
+ if (resolved === null)
419
+ return { kind: "retryable" };
420
+ return { kind: "ok", resolved };
421
+ }
360
422
  /**
361
423
  * Attempt to claim the token pair for `sessionId` with `verifier`. The verifier
362
424
  * is sent in the body; sil-web derives the same challenge server-side and the
@@ -396,9 +458,9 @@ export async function refreshSession(apiUrl, refreshToken) {
396
458
  * Fastify domain service, NOT sil-web). This is a bodyless `GET <silApiUrl>/identity`:
397
459
  * sil-api's authenticated self-read derives the principal from the JWT `sub`
398
460
  * (the `Authorization: Bearer <token>` header), loads that user's addresses,
399
- * and returns `{ id, name, addresses }` in the UCP envelope's `result`
400
- * (sil-api `handlers/identity.ts` GET route — declares only a response schema,
401
- * takes no request body). The verb is the whole point: POST hits the agent
461
+ * and returns `{ id, name, addresses }` (sil-api `handlers/identity.ts` GET route —
462
+ * declares only a response schema, takes no request body). The verb is the whole
463
+ * point: POST hits the agent
402
464
  * enrich-STUB (no name/addresses), GET hits the real self-read. No `agent_id`
403
465
  * or `on_behalf_of` is sent — the GET self-read has no body, so the principal
404
466
  * is unambiguously the token subject and the `principal_mismatch` 403 path is
@@ -473,6 +535,30 @@ export async function lookupCatalog(silApiUrl, token, ids) {
473
535
  const body = await readJsonBody(res);
474
536
  return classifyLookupResponse(res.status, body);
475
537
  }
538
+ /**
539
+ * Canonicalize coined spec definitions against sil-api's registry (the SAME origin
540
+ * as the identity read / `searchCatalog` / `lookupCatalog` — NOT sil-web; bare
541
+ * `/catalog/specs`, no `/api/v1`). The method submits `{ query, specs }` at mint/
542
+ * refresh and gets back the canonical `ns.key` per submitted spec — building NO UCP
543
+ * envelope and NO filter mapping (the wire body is EXACTLY `{ query, specs }`).
544
+ *
545
+ * The Bearer header is built HERE and never logged; the token travels only in the
546
+ * outbound request, never into the returned union. A network error / timeout maps
547
+ * to `retryable` (bare) so the method degrades gracefully to raw coined names — a
548
+ * registry hiccup never blocks the mint.
549
+ */
550
+ export async function specsCatalog(silApiUrl, token, params) {
551
+ const url = `${stripTrailingSlash(silApiUrl)}/catalog/specs`;
552
+ let res;
553
+ try {
554
+ res = await postJson(url, { query: params.query, specs: params.specs }, { authorization: `Bearer ${token}` });
555
+ }
556
+ catch {
557
+ return { kind: "retryable" };
558
+ }
559
+ const body = await readJsonBody(res);
560
+ return classifySpecsResponse(res.status, body);
561
+ }
476
562
  /**
477
563
  * SC7/F7 entry point: read the stored refresh token, exchange it via sil-web,
478
564
  * and rotate `tokens.json` with the new pair on success.
@@ -566,9 +652,9 @@ export async function refreshAndRetryOnce(first, isUnauthorized, retryWithToken)
566
652
  /**
567
653
  * Unwrap + narrow a sil-api identity response body to a typed `Identity`, or
568
654
  * null if it carries no usable identity. Defends against the latent wire shape:
569
- * the identity may be wrapped in the UCP envelope's `result` OR (if the
570
- * follow-on returns it bare) at the top level, so we try `result` first and
571
- * fall back to the body itself.
655
+ * the identity may be wrapped in a `result` field OR (if the follow-on returns it
656
+ * bare) at the top level, so we try `result` first and fall back to the body
657
+ * itself.
572
658
  *
573
659
  * A usable identity REQUIRES a non-empty `name` string (the authoritative human
574
660
  * name) and that `addresses` is an ARRAY — but the array may be EMPTY. sil-api
@@ -644,6 +730,9 @@ function extractForbiddenReason(body) {
644
730
  */
645
731
  function buildSearchBody(params) {
646
732
  const body = {};
733
+ // The agent's free-text `query` is forwarded VERBATIM. The plugin is pure
734
+ // transport — a `specs` predicate NEVER folds into `query` (that lossy/unsafe job
735
+ // belongs to the agent, which authors the free-text from the requirements).
647
736
  if (typeof params.query === "string")
648
737
  body["query"] = params.query;
649
738
  const filters = {};
@@ -666,6 +755,14 @@ function buildSearchBody(params) {
666
755
  filters["condition"] = params.condition;
667
756
  if (typeof params.available === "boolean")
668
757
  filters["available"] = params.available;
758
+ // The structured requirement predicates ride ONE namespaced well-known key —
759
+ // `filters.specs` holds the WHOLE array (never spread as `filters.<key>`, which
760
+ // would collide with a typed filter and fail-green on the open `SearchFilters`;
761
+ // never top-level — unlike the sil-private `local_merchants`, `specs` is a
762
+ // backend-bound filter). `hard` rides each entry UNCHANGED. A present-but-empty
763
+ // `[]` emits nothing (the query is unchanged, `filters.specs` omitted).
764
+ if (Array.isArray(params.specs) && params.specs.length > 0)
765
+ filters["specs"] = params.specs;
669
766
  if (Object.keys(filters).length > 0)
670
767
  body["filters"] = filters;
671
768
  // `local_merchants` is a sil-PRIVATE ranking bias — it rides at the TOP LEVEL of
@@ -695,9 +792,8 @@ function withUppercaseCountry(value) {
695
792
  /**
696
793
  * Unwrap + narrow a sil-api catalog-search response body to a typed
697
794
  * {@link SearchResult}, or null if it carries no usable products array. sil-api
698
- * emits a FLAT UCP envelope (`withUcpMeta(body) → { ucp, ...body }` —
699
- * sil-services `.../sil-api/src/envelope.ts`): `products` and `pagination` sit at
700
- * the TOP LEVEL beside `ucp`, there is NO `result` wrapper. Read them straight
795
+ * emits a FLAT body: `products` and `pagination` sit at the TOP LEVEL, there is
796
+ * NO `result` wrapper. Read them straight
701
797
  * off the body. (There is no nested-`result` fallback to keep: search has no
702
798
  * second route that ever returns one, so a `result`-wrapper expectation would be
703
799
  * dead weight and — worse — a latent false-green a stray `result` key could shadow
@@ -705,7 +801,7 @@ function withUppercaseCountry(value) {
705
801
  *
706
802
  * The load-bearing anti-false-green guard is the `Array.isArray(products)` check:
707
803
  * a 200 lacking a real top-level `products` array (a partial / garbage / stub
708
- * `{ stub: true }` body, or one carrying only `ucp` metadata) returns null →
804
+ * `{ stub: true }` body) returns null →
709
805
  * `retryable`, never a false-green empty match. An EMPTY array is a VALID empty
710
806
  * match (a genuine "nothing matched") and returns an empty `products` list —
711
807
  * distinct from the no-array guard. Individual products that are unusable (no
@@ -715,6 +811,11 @@ function withUppercaseCountry(value) {
715
811
  * The opaque cursor is hoisted from `pagination.cursor` and surfaced ONLY when
716
812
  * `pagination.has_next_page` is true (end-of-results is the absent cursor — never
717
813
  * derived from `products.length`).
814
+ *
815
+ * `specs_status` is read off the SAME flat envelope as a sibling of `products`
816
+ * (via {@link extractSpecsStatus}), so the observable per-predicate applied-status
817
+ * surfaces even on an empty match. It is informational — NEVER a purchasability
818
+ * gate; the `Array.isArray(products)` anti-false-green guard is unchanged.
718
819
  */
719
820
  function extractSearchResult(body) {
720
821
  const envelope = asRecord(body);
@@ -726,8 +827,43 @@ function extractSearchResult(body) {
726
827
  const products = rawProducts
727
828
  .map(projectProduct)
728
829
  .filter((p) => p !== null);
830
+ const result = { products };
729
831
  const cursor = extractCursor(envelope["pagination"]);
730
- return cursor === null ? { products } : { products, cursor };
832
+ if (cursor !== null)
833
+ result.cursor = cursor;
834
+ const specsStatus = extractSpecsStatus(envelope["specs_status"]);
835
+ if (specsStatus !== null)
836
+ result.specs_status = specsStatus;
837
+ return result;
838
+ }
839
+ /** Narrow the wire `specs_status` to {@link SpecStatus}[], or null to OMIT the
840
+ * key. Each usable entry needs a non-empty string `ns`, a non-empty string `key`,
841
+ * and a BOOLEAN `applied`; a malformed entry is DROPPED (never fabricated
842
+ * `applied:true`, never a crash). Returns null when the field is absent/non-array
843
+ * OR when no entry survives — the no-fabrication discipline: interpreting the
844
+ * ABSENCE of a status is reflection's job, not the tool's. A fully-`applied:false`
845
+ * array is the honest "not indexed yet" shape and passes through whole. */
846
+ function extractSpecsStatus(raw) {
847
+ if (!Array.isArray(raw))
848
+ return null;
849
+ const statuses = raw
850
+ .map((entry) => {
851
+ const obj = asRecord(entry);
852
+ if (obj === null)
853
+ return null;
854
+ const ns = obj["ns"];
855
+ const key = obj["key"];
856
+ const applied = obj["applied"];
857
+ if (typeof ns !== "string" || ns.length === 0)
858
+ return null;
859
+ if (typeof key !== "string" || key.length === 0)
860
+ return null;
861
+ if (typeof applied !== "boolean")
862
+ return null;
863
+ return { ns, key, applied };
864
+ })
865
+ .filter((s) => s !== null);
866
+ return statuses.length === 0 ? null : statuses;
731
867
  }
732
868
  /**
733
869
  * Project one `SilCatalogProduct` to the agent-facing {@link SearchProduct}, or
@@ -801,14 +937,13 @@ function projectVariant(raw) {
801
937
  /**
802
938
  * Unwrap + narrow a sil-api catalog-LOOKUP response body to a typed
803
939
  * {@link LookupResult}, or null if it carries no usable products array. Like
804
- * `extractSearchResult`, it reads sil-api's FLAT UCP envelope
805
- * (`withUcpMeta(body) → { ucp, ...body }`): `products` and `messages` sit at the
806
- * TOP LEVEL beside `ucp`, there is NO `result` wrapper — read them straight off
940
+ * `extractSearchResult`, it reads sil-api's FLAT body: `products` and `messages`
941
+ * sit at the TOP LEVEL, there is NO `result` wrapper — read them straight off
807
942
  * the body (no nested-`result` fallback; lookup has no route that returns one).
808
943
  *
809
944
  * It shares search's load-bearing anti-false-green guard — `Array.isArray(products)`
810
945
  * on the TOP-LEVEL `products`; a 200 lacking it (partial / garbage / stub
811
- * `{ stub: true }`, or only `ucp` metadata) returns null → `retryable`. An EMPTY
946
+ * `{ stub: true }`) returns null → `retryable`. An EMPTY
812
947
  * array is a VALID all-missed lookup (the products gate passes; `not_found`
813
948
  * carries the ids) — distinct from the no-array guard. The two structural deltas
814
949
  * from search:
@@ -835,6 +970,120 @@ function extractLookupResult(body) {
835
970
  const notFound = extractNotFound(envelope["messages"]);
836
971
  return notFound.length === 0 ? { products } : { products, not_found: notFound };
837
972
  }
973
+ /** The closed spec value-types, the anti-false-green enum for a resolution's
974
+ * `data_type` (the vocabulary `namespace`/`key` stay open). */
975
+ const SPEC_DATA_TYPES = ["number", "text", "boolean", "enum"];
976
+ function isSpecDataType(value) {
977
+ return typeof value === "string" && SPEC_DATA_TYPES.includes(value);
978
+ }
979
+ /**
980
+ * Narrow a sil-api spec-registry response body to the typed {@link SpecResolution}[],
981
+ * or null if it carries no usable resolution array. sil-api emits a FLAT body:
982
+ * `resolved` sits at the TOP LEVEL, there is NO `ucp` meta and NO `result` wrapper —
983
+ * read it straight off the body.
984
+ *
985
+ * The load-bearing anti-false-green guard is `Array.isArray(resolved)` AND a
986
+ * NON-EMPTY array. This is STRICTER than search's products gate: the server owes a
987
+ * 1:1 resolution for every submitted spec, so there is NO valid empty-match — an
988
+ * empty `resolved: []` is itself a malformed 200 and returns null → `retryable`.
989
+ *
990
+ * FAIL-WHOLE (design decision, product-owner AC1/AC9 "no partial adopt"): because
991
+ * the method cannot adopt a canonical name it never got back, a SINGLE malformed
992
+ * entry (missing/blank `canonical` ref, bad `status`, bad `data_type`, missing flag)
993
+ * falls the WHOLE 200 to `retryable` — unlike search, which drops one unusable
994
+ * product from a best-effort list. Every entry must project cleanly or none do.
995
+ */
996
+ function extractSpecsResult(body) {
997
+ const envelope = asRecord(body);
998
+ if (envelope === null)
999
+ return null;
1000
+ const rawResolved = envelope["resolved"];
1001
+ if (!Array.isArray(rawResolved) || rawResolved.length === 0)
1002
+ return null;
1003
+ const resolved = [];
1004
+ for (const raw of rawResolved) {
1005
+ const one = projectResolution(raw);
1006
+ if (one === null)
1007
+ return null; // fail-whole: no half-canonical vocabulary
1008
+ resolved.push(one);
1009
+ }
1010
+ return resolved;
1011
+ }
1012
+ /**
1013
+ * Project ONE wire resolution to the typed {@link SpecResolution}, or null if any
1014
+ * required field is malformed (fail-whole, per {@link extractSpecsResult}). Requires
1015
+ * the flat canonical definition (`namespace`/`key`/`display_name` non-empty,
1016
+ * `data_type` in the closed enum), the `submitted`/`canonical` refs, a valid
1017
+ * `status`, and both boolean capability flags. Optional `description`/`unit`/
1018
+ * `allowed_values` pass through when the right type. No `any`, no unchecked `as`.
1019
+ */
1020
+ function projectResolution(raw) {
1021
+ const obj = asRecord(raw);
1022
+ if (obj === null)
1023
+ return null;
1024
+ const namespace = obj["namespace"];
1025
+ const key = obj["key"];
1026
+ const displayName = obj["display_name"];
1027
+ if (typeof namespace !== "string" || namespace.length === 0)
1028
+ return null;
1029
+ if (typeof key !== "string" || key.length === 0)
1030
+ return null;
1031
+ if (typeof displayName !== "string" || displayName.length === 0)
1032
+ return null;
1033
+ const dataType = obj["data_type"];
1034
+ if (!isSpecDataType(dataType))
1035
+ return null;
1036
+ const submitted = extractSpecRef(obj["submitted"]);
1037
+ const canonical = extractSpecRef(obj["canonical"]);
1038
+ if (submitted === null || canonical === null)
1039
+ return null;
1040
+ const status = obj["status"];
1041
+ if (status !== "matched" && status !== "created")
1042
+ return null;
1043
+ const isFilterable = obj["is_filterable"];
1044
+ const isComparable = obj["is_comparable"];
1045
+ if (typeof isFilterable !== "boolean" || typeof isComparable !== "boolean")
1046
+ return null;
1047
+ const result = {
1048
+ namespace,
1049
+ key,
1050
+ display_name: displayName,
1051
+ data_type: dataType,
1052
+ submitted,
1053
+ canonical,
1054
+ status,
1055
+ is_filterable: isFilterable,
1056
+ is_comparable: isComparable,
1057
+ };
1058
+ const description = obj["description"];
1059
+ if (typeof description === "string")
1060
+ result.description = description;
1061
+ const unit = obj["unit"];
1062
+ if (typeof unit === "string")
1063
+ result.unit = unit;
1064
+ const allowedValues = obj["allowed_values"];
1065
+ if (Array.isArray(allowedValues)) {
1066
+ const values = allowedValues.filter((v) => typeof v === "string");
1067
+ if (values.length > 0)
1068
+ result.allowed_values = values;
1069
+ }
1070
+ return result;
1071
+ }
1072
+ /** Narrow a wire `{ namespace, key }` reference (the `submitted` / `canonical`
1073
+ * fields), or null if either is missing/blank — the load-bearing gate a resolution
1074
+ * needs so the method can adopt the canonical name. */
1075
+ function extractSpecRef(raw) {
1076
+ const obj = asRecord(raw);
1077
+ if (obj === null)
1078
+ return null;
1079
+ const namespace = obj["namespace"];
1080
+ const key = obj["key"];
1081
+ if (typeof namespace !== "string" || namespace.length === 0)
1082
+ return null;
1083
+ if (typeof key !== "string" || key.length === 0)
1084
+ return null;
1085
+ return { namespace, key };
1086
+ }
838
1087
  /**
839
1088
  * Project one `SilCatalogProduct` to the agent-facing {@link LookupProduct}, or
840
1089
  * null if it is unusable. RICHER than search's `projectProduct`: carries the