sil-openclaw 0.2.2 → 0.2.3
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/CHANGELOG.md +49 -0
- package/README.md +7 -7
- package/dist/lib/sil-client.js +203 -28
- package/dist/tools/catalog.js +167 -68
- package/dist/tools/identity.js +11 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,55 @@ release (`clawhub package publish --changelog`). See [README](./README.md#releas
|
|
|
10
10
|
|
|
11
11
|
## [Unreleased]
|
|
12
12
|
|
|
13
|
+
## [0.2.3] - 2026-06-16
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- **`sil_search` and `sil_product_get` now surface evaluate-before-buy detail.**
|
|
18
|
+
Beyond the purchasable variant, results carry — where the source provides them —
|
|
19
|
+
the product/variant `url` (the page to VIEW / learn more, distinct from the
|
|
20
|
+
buy-committing `checkout_url`), a short `description`, `media`, the product
|
|
21
|
+
`options` menu, the `seller` with its policy/info links (shipping & return/refund
|
|
22
|
+
policies, terms), and arbitrary `metadata`. The tool descriptions teach the three
|
|
23
|
+
distinct actions — VIEW (`url`), DIG IN (`seller.links`), BUY (`checkout_url`) — so
|
|
24
|
+
an agent can compare, answer "what's their return policy?", and hand back the right
|
|
25
|
+
link without conflating viewing with buying. (#23)
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- **`sil_search`: replaced the `ships_from` filter with a `local_merchants` boolean
|
|
30
|
+
bias.** It nudges shops based in the shopper's own country up the ranking,
|
|
31
|
+
best-effort — it does NOT restrict results to them (some local shops go
|
|
32
|
+
undetected, some non-local ones still appear). The agent passes no country: sil
|
|
33
|
+
resolves it server-side from the registered address. To actually surface local
|
|
34
|
+
stores, issue the `query` in the shopper's own language (a French query surfaces
|
|
35
|
+
French shops). (#20)
|
|
36
|
+
|
|
37
|
+
### Fixed
|
|
38
|
+
|
|
39
|
+
- **A catalog `422 source_rejected` is now classified non-retryable
|
|
40
|
+
`invalid_request`, not source-named `retryable`.** A real source *rejection*
|
|
41
|
+
(the source looked at the request and refused it — it can never succeed
|
|
42
|
+
unchanged) was falling through to `retryableFromBody`, and because the 422 body
|
|
43
|
+
carries a `source` it surfaced as the source-named `retryable` (outcome b) — a
|
|
44
|
+
false instruction that told the agent to retry a doomed request while the real
|
|
45
|
+
upstream cause was buried as a transient `detail`. Both catalog classifiers
|
|
46
|
+
(`classifySearchResponse` / `classifyLookupResponse`, backing `sil_search` /
|
|
47
|
+
`sil_product_get`) now special-case `422 → invalid_request` carrying the
|
|
48
|
+
upstream `{ error, message }`, mirroring the existing `400` arm. The narrowing
|
|
49
|
+
is exact: a `5xx`/`429 source_unavailable` stays `retryable`.
|
|
50
|
+
|
|
51
|
+
- **`sil_search` / `sil_product_get` surface `user_not_provisioned` as a distinct
|
|
52
|
+
`forbidden` outcome and clear the structurally-dead token**, so the next
|
|
53
|
+
`sil_register` re-onboards the user instead of short-circuiting to
|
|
54
|
+
`already_registered`. A `principal_mismatch` or unknown 403 reason stays
|
|
55
|
+
recoverable and is NOT cleared. (#21)
|
|
56
|
+
|
|
57
|
+
- **Catalog transient (5xx) failures now name the failed source** when the wire
|
|
58
|
+
carries one — "the catalog source X is temporarily unavailable; sil itself is
|
|
59
|
+
fine" — instead of mis-attributing one degraded source to sil being down, which
|
|
60
|
+
would make the agent abandon a healthy platform. (#19)
|
|
61
|
+
|
|
13
62
|
## [0.2.2] - 2026-06-13
|
|
14
63
|
|
|
15
64
|
### Fixed
|
package/README.md
CHANGED
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
*You say what you want. Your agent searches the catalog, compares, and hands you a ready-to-buy link.*
|
|
15
15
|
*No store. No tabs. No forms.*
|
|
16
16
|
|
|
17
|
-
[](
|
|
18
|
-
[](https://github.com/Context4GPTs/sil-openclaw/blob/main/LICENSE)
|
|
18
|
+
[](https://www.npmjs.com/package/sil-openclaw)
|
|
19
19
|
[](https://clawhub.com)
|
|
20
20
|
[](https://github.com/Context4GPTs/sil-openclaw)
|
|
21
|
-
[](https://github.com/Context4GPTs/sil-openclaw/commits)
|
|
21
|
+
[](https://github.com/Context4GPTs/sil-openclaw/commits/main)
|
|
22
22
|
|
|
23
|
-
**[Website](https://4gpts.com)** · **[Changelog](
|
|
23
|
+
**[Website](https://4gpts.com)** · **[Changelog](https://github.com/Context4GPTs/sil-openclaw/blob/main/CHANGELOG.md)** · **[Security](https://github.com/Context4GPTs/sil-openclaw/blob/main/SECURITY.md)** · **[Follow on X](https://x.com/4gpts)**
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
32
|
# ClawHub (recommended)
|
|
33
|
-
openclaw plugins install clawhub
|
|
33
|
+
openclaw plugins install clawhub:@4gpts/sil
|
|
34
34
|
|
|
35
35
|
# npm
|
|
36
36
|
openclaw plugins install sil-openclaw
|
|
@@ -117,8 +117,8 @@ Namespaced `sil_*` so they never collide with other plugins. Your agent calls th
|
|
|
117
117
|
|
|
118
118
|
| Tool | What it does |
|
|
119
119
|
|---|---|
|
|
120
|
-
| `sil_search` | Search for purchasable products. A free-text `query` plus optional filters: `category`, `price_min`/`price_max`, `ship_to` (delivery destination — leave empty to ship to your registered address), `
|
|
121
|
-
| `sil_product_get` | Resolve `ids` you already hold to full products in UCP shape — description
|
|
120
|
+
| `sil_search` | Search for purchasable products. A free-text `query` plus optional filters: `category`, `price_min`/`price_max`, `ship_to` (delivery destination — leave empty to ship to your registered address), `condition` (`new` / `secondhand`), `available`, and `local_merchants` (best-effort bias toward shops in the user's own country). Results are **localized** to the shopper — issue the `query` in their own language for the best local results (e.g. search in French for French stores). Returns a ranked list of variants — each with `id`, `title`, `price`, `availability`, `checkout_url`, `source`, plus (where the source provides them) evaluate-before-buy detail: a product/variant `url` to view, a `description`, `media`, the product `options`, and the `seller`'s **shipping & return policy links** — and a pagination `cursor`. Location filters take ISO codes (`US`, `CA`), not place names. |
|
|
121
|
+
| `sil_product_get` | Resolve `ids` you already hold to full products in UCP shape — `description`, `options`, `media`, the `seller`'s shipping & return policy links, and the featured purchasable variant with fresh `price`, `availability`, `url` (the page to view), and `checkout_url` (the link that buys). Re-fetch right before buying; those values are point-in-time, not guarantees. Ids that no longer resolve come back in `not_found`. |
|
|
122
122
|
|
|
123
123
|
---
|
|
124
124
|
|
package/dist/lib/sil-client.js
CHANGED
|
@@ -245,6 +245,12 @@ export function classifyIdentityResponse(status, body) {
|
|
|
245
245
|
* retry or re-register)
|
|
246
246
|
* 401 → unauthorized (the refresh trigger — the caller drives transparent
|
|
247
247
|
* refresh-and-retry-once via `refreshAndRetryOnce`, not terminal)
|
|
248
|
+
* 403 → forbidden (terminal-but-recoverable; carries the actionable reason
|
|
249
|
+
* `user_not_provisioned`/`principal_mismatch`, defaulting to the generic
|
|
250
|
+
* `"forbidden"` marker on an unexpected body — parity with
|
|
251
|
+
* `classifyIdentityResponse`). A 403 is NOT a 401: it surfaces as the
|
|
252
|
+
* shared forbidden envelope, never the false-transient `retryable`, and a
|
|
253
|
+
* valid-but-unprovisioned token gains nothing from a refresh.
|
|
248
254
|
* 5xx / other non-200 → retryable
|
|
249
255
|
* 200 → read `products` off sil-api's FLAT envelope (`{ ucp, products,
|
|
250
256
|
* pagination? }` — top level, no `result` wrapper), normalize, and require
|
|
@@ -258,7 +264,7 @@ export function classifyIdentityResponse(status, body) {
|
|
|
258
264
|
*
|
|
259
265
|
* Pure and exported — unit-tested in isolation like `classifyIdentityResponse`;
|
|
260
266
|
* conflating the empty-match success with a partial-200 false-green, or with the
|
|
261
|
-
* 400/401/5xx error classes, is the highest-risk subtle bug in this flow.
|
|
267
|
+
* 400/401/403/5xx error classes, is the highest-risk subtle bug in this flow.
|
|
262
268
|
*/
|
|
263
269
|
export function classifySearchResponse(status, body) {
|
|
264
270
|
if (status === 400) {
|
|
@@ -267,8 +273,22 @@ export function classifySearchResponse(status, body) {
|
|
|
267
273
|
}
|
|
268
274
|
if (status === 401)
|
|
269
275
|
return { kind: "unauthorized" };
|
|
276
|
+
if (status === 403)
|
|
277
|
+
return { kind: "forbidden", reason: extractForbiddenReason(body) };
|
|
278
|
+
// 422 source_rejected: the source LOOKED at this exact request and refused it —
|
|
279
|
+
// it can never succeed unchanged, so it is non-retryable invalid_request carrying
|
|
280
|
+
// the real upstream cause, NOT the source-named `retryable` the fallthrough below
|
|
281
|
+
// would produce (a 422 body names a `source`, so `retryableFromBody` would emit
|
|
282
|
+
// outcome (b) and tell the agent to retry a doomed request). This is the third
|
|
283
|
+
// arm of the 401-vs-403-vs-422 split: 401 refresh-and-retry, 403 forbidden
|
|
284
|
+
// (refresh won't help), 422 invalid_request (fix the request, don't retry).
|
|
285
|
+
// Matches EXACTLY 422 — a 5xx/429 source_unavailable stays `retryable` (outcome b).
|
|
286
|
+
if (status === 422) {
|
|
287
|
+
const { error, message } = extractApiError(body);
|
|
288
|
+
return { kind: "invalid_request", error, message };
|
|
289
|
+
}
|
|
270
290
|
if (status !== 200)
|
|
271
|
-
return
|
|
291
|
+
return retryableFromBody(body);
|
|
272
292
|
const result = extractSearchResult(body);
|
|
273
293
|
if (result === null)
|
|
274
294
|
return { kind: "retryable" };
|
|
@@ -286,6 +306,12 @@ export function classifySearchResponse(status, body) {
|
|
|
286
306
|
* which never arises on the lookup route; do not special-case it.)
|
|
287
307
|
* 401 → unauthorized (the refresh trigger — the caller drives transparent
|
|
288
308
|
* refresh-and-retry-once via `refreshAndRetryOnce`, parity with search)
|
|
309
|
+
* 403 → forbidden (terminal-but-recoverable; carries the actionable reason
|
|
310
|
+
* `user_not_provisioned`/`principal_mismatch`, defaulting to the generic
|
|
311
|
+
* `"forbidden"` marker on an unexpected body — parity with search and
|
|
312
|
+
* `classifyIdentityResponse`). A 403 surfaces as the shared forbidden
|
|
313
|
+
* envelope, never the false-transient `retryable`; it is NOT a 401, so no
|
|
314
|
+
* refresh is triggered.
|
|
289
315
|
* 5xx / other non-200 → retryable
|
|
290
316
|
* 200 → read `products` off sil-api's FLAT envelope (`{ ucp, products,
|
|
291
317
|
* messages? }` — top level, no `result` wrapper), normalize, and require
|
|
@@ -312,8 +338,20 @@ export function classifyLookupResponse(status, body) {
|
|
|
312
338
|
}
|
|
313
339
|
if (status === 401)
|
|
314
340
|
return { kind: "unauthorized" };
|
|
341
|
+
if (status === 403)
|
|
342
|
+
return { kind: "forbidden", reason: extractForbiddenReason(body) };
|
|
343
|
+
// 422 source_rejected: the twin seam of `classifySearchResponse` — sil-api emits
|
|
344
|
+
// 422 on the SHARED source layer backing both catalog routes, so a source-rejected
|
|
345
|
+
// lookup is the same non-retryable invalid_request, carrying the upstream cause,
|
|
346
|
+
// NOT the source-named `retryable` the fallthrough would produce. Same one error
|
|
347
|
+
// vocabulary across both catalog tools (see this fn's doc-comment). Matches EXACTLY
|
|
348
|
+
// 422 — a 5xx/429 source_unavailable stays `retryable` (outcome b).
|
|
349
|
+
if (status === 422) {
|
|
350
|
+
const { error, message } = extractApiError(body);
|
|
351
|
+
return { kind: "invalid_request", error, message };
|
|
352
|
+
}
|
|
315
353
|
if (status !== 200)
|
|
316
|
-
return
|
|
354
|
+
return retryableFromBody(body);
|
|
317
355
|
const result = extractLookupResult(body);
|
|
318
356
|
if (result === null)
|
|
319
357
|
return { kind: "retryable" };
|
|
@@ -576,8 +614,8 @@ function extractForbiddenReason(body) {
|
|
|
576
614
|
* The tool clamps nothing and validates no cursor opacity — sil-api owns those.
|
|
577
615
|
*
|
|
578
616
|
* THE load-bearing rename: the agent arg `ship_to` (singular) becomes the wire key
|
|
579
|
-
* `filters.ships_to` (plural). `
|
|
580
|
-
*
|
|
617
|
+
* `filters.ships_to` (plural). `condition`/`available` keep their name under
|
|
618
|
+
* `filters.*`. These three ride sil-api's OPEN `SearchFilters`
|
|
581
619
|
* (`additionalProperties: true`), which SILENTLY accepts an unknown key — so the
|
|
582
620
|
* exact emitted key name is the only thing standing between a working serviceability
|
|
583
621
|
* filter and a no-op (a wrong rename fails GREEN). Each is forwarded ONLY when
|
|
@@ -586,13 +624,23 @@ function extractForbiddenReason(body) {
|
|
|
586
624
|
* `available: false` is narrowed with `typeof === "boolean"`, never `if (v)`, so the
|
|
587
625
|
* meaningful `false` (include unavailable items) survives.
|
|
588
626
|
*
|
|
627
|
+
* `local_merchants` is the ONE field that does NOT ride `filters`. It is a
|
|
628
|
+
* sil-PRIVATE ranking-bias signal, not a UCP/Global-Catalog filter — `filters` is
|
|
629
|
+
* forwarded to the cross-shop Global Catalog, whose OPEN schema would silently
|
|
630
|
+
* accept and ignore an unknown `local_merchants` key (the exact wrong-placement
|
|
631
|
+
* no-op the rename hazard above warns of). So it is emitted at the TOP LEVEL of the
|
|
632
|
+
* body (beside `query`/`filters`/`pagination`), and ONLY when exactly `true`: unlike
|
|
633
|
+
* `available: false` (a meaningful include-unavailable signal that survives), a
|
|
634
|
+
* `false` bias carries NO signal (== the server's unbiased default), so `false` and
|
|
635
|
+
* absent both omit the key (narrow on the VALUE, not just the type — emit iff true).
|
|
636
|
+
*
|
|
589
637
|
* COUNTRY-CASE NORMALIZATION is the wire layer's job (the read site owns FORMAT
|
|
590
|
-
* rejection): `ships_to.country`
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
*
|
|
638
|
+
* rejection): `ships_to.country` is emitted UPPERCASE (`us` → `US`), the alpha-2
|
|
639
|
+
* contract `@sil/schemas` `ShipTo` mirrors byte-for-byte. A lowercase code on the
|
|
640
|
+
* wire would diverge from the sibling and (depending on the server's
|
|
641
|
+
* case-sensitivity) silently mis-filter. `region` and `postal_code` are forwarded
|
|
642
|
+
* VERBATIM — they passed their pattern at the read site, and the wire normalizes
|
|
643
|
+
* only country case.
|
|
596
644
|
*/
|
|
597
645
|
function buildSearchBody(params) {
|
|
598
646
|
const body = {};
|
|
@@ -609,20 +657,25 @@ function buildSearchBody(params) {
|
|
|
609
657
|
price["max"] = params.price_max;
|
|
610
658
|
if (Object.keys(price).length > 0)
|
|
611
659
|
filters["price"] = price;
|
|
612
|
-
// The
|
|
613
|
-
// rename happens here; the other
|
|
614
|
-
//
|
|
660
|
+
// The three serviceability/localization filters — the `ship_to` → `ships_to`
|
|
661
|
+
// rename happens here; the other two keep their name. Country is uppercased on
|
|
662
|
+
// emit (region/postal forwarded verbatim); the other two pass through as-is.
|
|
615
663
|
if (params.ship_to !== undefined)
|
|
616
664
|
filters["ships_to"] = withUppercaseCountry(params.ship_to);
|
|
617
|
-
if (params.ships_from !== undefined) {
|
|
618
|
-
filters["ships_from"] = withUppercaseCountry(params.ships_from);
|
|
619
|
-
}
|
|
620
665
|
if (params.condition !== undefined)
|
|
621
666
|
filters["condition"] = params.condition;
|
|
622
667
|
if (typeof params.available === "boolean")
|
|
623
668
|
filters["available"] = params.available;
|
|
624
669
|
if (Object.keys(filters).length > 0)
|
|
625
670
|
body["filters"] = filters;
|
|
671
|
+
// `local_merchants` is a sil-PRIVATE ranking bias — it rides at the TOP LEVEL of
|
|
672
|
+
// the body (a sibling of `query`/`filters`/`pagination`), NEVER under `filters`
|
|
673
|
+
// (those are forwarded to the Global Catalog, which would silently swallow it).
|
|
674
|
+
// Emitted ONLY when exactly `true`: a `false`/absent bias carries no signal (it is
|
|
675
|
+
// the server's unbiased default), so — unlike `available:false` — it is omitted.
|
|
676
|
+
// Narrow on the VALUE, not just the type: `=== true`, never a truthiness coerce.
|
|
677
|
+
if (params.local_merchants === true)
|
|
678
|
+
body["local_merchants"] = true;
|
|
626
679
|
const pagination = {};
|
|
627
680
|
if (typeof params.cursor === "string")
|
|
628
681
|
pagination["cursor"] = params.cursor;
|
|
@@ -632,10 +685,10 @@ function buildSearchBody(params) {
|
|
|
632
685
|
body["pagination"] = pagination;
|
|
633
686
|
return body;
|
|
634
687
|
}
|
|
635
|
-
/** Emit a ship-to
|
|
636
|
-
*
|
|
637
|
-
* preserved verbatim. The spread-then-overwrite keeps the shape generic over
|
|
638
|
-
* {
|
|
688
|
+
/** Emit a ship-to object with its alpha-2 `country` UPPERCASED on the wire
|
|
689
|
+
* (`us` → `US`); every other field (`region`/`postal_code` on {@link ShipTo}) is
|
|
690
|
+
* preserved verbatim. The spread-then-overwrite keeps the shape generic over any
|
|
691
|
+
* `{ country }`-bearing value without reshaping or dropping a field. */
|
|
639
692
|
function withUppercaseCountry(value) {
|
|
640
693
|
return { ...value, country: value.country.toUpperCase() };
|
|
641
694
|
}
|
|
@@ -704,13 +757,20 @@ function projectProduct(raw) {
|
|
|
704
757
|
const variant = projectVariant(variants[0]);
|
|
705
758
|
if (variant === null)
|
|
706
759
|
return null;
|
|
707
|
-
|
|
760
|
+
const result = { id: productId, title: productTitle, source, variant };
|
|
761
|
+
attachProductEnrichment(result, product);
|
|
762
|
+
return result;
|
|
708
763
|
}
|
|
709
764
|
/**
|
|
710
765
|
* Project a `SilCatalogVariant` to the agent-facing {@link SearchVariant}, or
|
|
711
766
|
* null if it is not a usable purchasable variant. Requires `id`, `title`, a price
|
|
712
767
|
* object, and a non-empty `checkout_url`; `price`/`availability` pass through
|
|
713
|
-
* opaque.
|
|
768
|
+
* opaque. The PURCHASABILITY gate is unchanged — the enriched fields are additive
|
|
769
|
+
* context, never a new gate: a variant lacking a non-empty `checkout_url` is still
|
|
770
|
+
* dropped even when it carries `url`/`seller`/`media`.
|
|
771
|
+
*
|
|
772
|
+
* The enriched per-variant surface (`url`/`seller`/`media`/`metadata`) is attached
|
|
773
|
+
* via {@link attachVariantEnrichment}, each ONLY when present.
|
|
714
774
|
*/
|
|
715
775
|
function projectVariant(raw) {
|
|
716
776
|
const variant = asRecord(raw);
|
|
@@ -728,13 +788,15 @@ function projectVariant(raw) {
|
|
|
728
788
|
const price = extractPrice(variant["price"]);
|
|
729
789
|
if (price === null)
|
|
730
790
|
return null;
|
|
731
|
-
|
|
791
|
+
const result = {
|
|
732
792
|
id,
|
|
733
793
|
title,
|
|
734
794
|
price,
|
|
735
795
|
availability: extractAvailability(variant["availability"]),
|
|
736
796
|
checkout_url: checkoutUrl,
|
|
737
797
|
};
|
|
798
|
+
attachVariantEnrichment(result, variant);
|
|
799
|
+
return result;
|
|
738
800
|
}
|
|
739
801
|
/**
|
|
740
802
|
* Unwrap + narrow a sil-api catalog-LOOKUP response body to a typed
|
|
@@ -797,9 +859,6 @@ function projectLookupProduct(raw) {
|
|
|
797
859
|
return null;
|
|
798
860
|
if (typeof source !== "string" || source.length === 0)
|
|
799
861
|
return null;
|
|
800
|
-
const description = asRecord(product["description"]);
|
|
801
|
-
if (description === null)
|
|
802
|
-
return null;
|
|
803
862
|
const priceRange = product["price_range"];
|
|
804
863
|
if (asRecord(priceRange) === null)
|
|
805
864
|
return null;
|
|
@@ -812,7 +871,6 @@ function projectLookupProduct(raw) {
|
|
|
812
871
|
const result = {
|
|
813
872
|
id,
|
|
814
873
|
title,
|
|
815
|
-
description,
|
|
816
874
|
price_range: priceRange,
|
|
817
875
|
source,
|
|
818
876
|
variant,
|
|
@@ -823,6 +881,11 @@ function projectLookupProduct(raw) {
|
|
|
823
881
|
const handle = product["handle"];
|
|
824
882
|
if (typeof handle === "string" && handle.length > 0)
|
|
825
883
|
result.handle = handle;
|
|
884
|
+
// `description` is now the `{ plain }` lift (ONE vocabulary with search), NOT the
|
|
885
|
+
// whole opaque object — omitted entirely when `plain` is absent/empty. Reuses the
|
|
886
|
+
// SAME product-enrichment attach as search so both tools surface the identical
|
|
887
|
+
// enriched shape (`url`/`description`/`media`/`options`/`metadata`).
|
|
888
|
+
attachProductEnrichment(result, product);
|
|
826
889
|
return result;
|
|
827
890
|
}
|
|
828
891
|
/**
|
|
@@ -865,6 +928,10 @@ function projectLookupVariant(raw) {
|
|
|
865
928
|
const inputs = extractInputs(variant["inputs"]);
|
|
866
929
|
if (inputs !== null)
|
|
867
930
|
result.inputs = inputs;
|
|
931
|
+
// The SAME enriched per-variant surface as search (ONE vocabulary):
|
|
932
|
+
// `url`/`seller`/`media`/`metadata`, each only when present. The variant's
|
|
933
|
+
// `options` SELECTIONS above and these enriched fields are distinct, additive.
|
|
934
|
+
attachVariantEnrichment(result, variant);
|
|
868
935
|
return result;
|
|
869
936
|
}
|
|
870
937
|
/** Pass a wire array of objects through OPAQUE — filter to plain objects, preserve
|
|
@@ -881,6 +948,80 @@ function passThroughObjects(raw) {
|
|
|
881
948
|
const objects = raw.filter((o) => asRecord(o) !== null);
|
|
882
949
|
return objects.length === 0 ? null : objects;
|
|
883
950
|
}
|
|
951
|
+
/** Pass a single wire OBJECT through OPAQUE — forward it verbatim when it is a
|
|
952
|
+
* plain object, never reading or remapping individual fields. The single-object
|
|
953
|
+
* counterpart to {@link passThroughObjects}, for `seller` and `metadata`: contextual
|
|
954
|
+
* data the tool SURFACES but does not interpret. This is the load-bearing
|
|
955
|
+
* narrow-vs-pass-through guard ([[sil-shared-catalog-client]]) — a typed
|
|
956
|
+
* `{ name, links }` narrow on `seller` would silently DROP the Shopify extension
|
|
957
|
+
* keys (`seller.url`/`seller.domain`) the source attaches, and pass a naive fixture;
|
|
958
|
+
* opaque pass-through keeps both the base shape and any extension/drift. An ARRAY is
|
|
959
|
+
* NOT a usable object here (a `seller`/`metadata` that arrived as `[]` is garbage),
|
|
960
|
+
* so arrays return null and the caller omits the key. */
|
|
961
|
+
function passThroughObject(raw) {
|
|
962
|
+
return raw !== null && typeof raw === "object" && !Array.isArray(raw)
|
|
963
|
+
? raw
|
|
964
|
+
: null;
|
|
965
|
+
}
|
|
966
|
+
/** Lift the agent-facing {@link ProductDescription} (`{ plain }`) from a wire
|
|
967
|
+
* `description` object, or null to OMIT. Surfaces ONLY the `plain` UCP format, and
|
|
968
|
+
* ONLY when it is a non-empty string — `html`/`markdown` are never substituted into
|
|
969
|
+
* `plain` (the spec flags `html` as untrusted rich text), and an absent/empty `plain`
|
|
970
|
+
* omits the whole `description` key. This is the one SCALAR read in the enriched
|
|
971
|
+
* surface (a stable, named UCP sub-field), and lifting it identically on both catalog
|
|
972
|
+
* tools is what keeps them on ONE `description` shape. */
|
|
973
|
+
function liftDescriptionPlain(raw) {
|
|
974
|
+
const obj = asRecord(raw);
|
|
975
|
+
if (obj === null)
|
|
976
|
+
return null;
|
|
977
|
+
const plain = obj["plain"];
|
|
978
|
+
return typeof plain === "string" && plain.length > 0 ? { plain } : null;
|
|
979
|
+
}
|
|
980
|
+
/** Attach the enriched PRODUCT surface (`url`/`description`/`media`/`options`/
|
|
981
|
+
* `metadata`) onto a projected product, each ONLY when present on the wire object.
|
|
982
|
+
* Shared verbatim by `projectProduct` (search) and `projectLookupProduct` (lookup)
|
|
983
|
+
* so BOTH tools surface the IDENTICAL enriched shape — the ONE-vocabulary property.
|
|
984
|
+
* Mutates `target` in place (it is a freshly-built projection the caller owns). Every
|
|
985
|
+
* field is OPAQUE pass-through keyed on PRESENCE; the only scalar read is
|
|
986
|
+
* `description.plain`. Omit-when-absent is per-field — an absent / empty-`plain` /
|
|
987
|
+
* no-`metadata` / all-garbage-array field leaves its key off entirely (no null/''/[]). */
|
|
988
|
+
function attachProductEnrichment(target, product) {
|
|
989
|
+
const url = product["url"];
|
|
990
|
+
if (typeof url === "string" && url.length > 0)
|
|
991
|
+
target.url = url;
|
|
992
|
+
const description = liftDescriptionPlain(product["description"]);
|
|
993
|
+
if (description !== null)
|
|
994
|
+
target.description = description;
|
|
995
|
+
const media = passThroughObjects(product["media"]);
|
|
996
|
+
if (media !== null)
|
|
997
|
+
target.media = media;
|
|
998
|
+
const options = passThroughObjects(product["options"]);
|
|
999
|
+
if (options !== null)
|
|
1000
|
+
target.options = options;
|
|
1001
|
+
const metadata = passThroughObject(product["metadata"]);
|
|
1002
|
+
if (metadata !== null)
|
|
1003
|
+
target.metadata = metadata;
|
|
1004
|
+
}
|
|
1005
|
+
/** Attach the enriched per-VARIANT surface (`url`/`seller`/`media`/`metadata`) onto a
|
|
1006
|
+
* projected variant, each ONLY when present. Shared verbatim by `projectVariant`
|
|
1007
|
+
* (search) and `projectLookupVariant` (lookup) — the variant half of the
|
|
1008
|
+
* ONE-vocabulary property. `seller` (incl. `seller.links[]`) and `metadata` are
|
|
1009
|
+
* single-object opaque pass-through; `media` is array pass-through. Same
|
|
1010
|
+
* omit-when-absent, per-field, never-narrow discipline as the product surface. */
|
|
1011
|
+
function attachVariantEnrichment(target, variant) {
|
|
1012
|
+
const url = variant["url"];
|
|
1013
|
+
if (typeof url === "string" && url.length > 0)
|
|
1014
|
+
target.url = url;
|
|
1015
|
+
const seller = passThroughObject(variant["seller"]);
|
|
1016
|
+
if (seller !== null)
|
|
1017
|
+
target.seller = seller;
|
|
1018
|
+
const media = passThroughObjects(variant["media"]);
|
|
1019
|
+
if (media !== null)
|
|
1020
|
+
target.media = media;
|
|
1021
|
+
const metadata = passThroughObject(variant["metadata"]);
|
|
1022
|
+
if (metadata !== null)
|
|
1023
|
+
target.metadata = metadata;
|
|
1024
|
+
}
|
|
884
1025
|
/** Narrow a wire `inputs` correlation array to {@link LookupInput}[] — each entry
|
|
885
1026
|
* needs a non-empty `id` (the request id that resolved to this variant); a missing
|
|
886
1027
|
* or non-string `match` is dropped (not coerced). Returns null when the field is
|
|
@@ -968,6 +1109,40 @@ function extractCursor(raw) {
|
|
|
968
1109
|
const cursor = obj["cursor"];
|
|
969
1110
|
return typeof cursor === "string" && cursor.length > 0 ? cursor : null;
|
|
970
1111
|
}
|
|
1112
|
+
/**
|
|
1113
|
+
* Build the `retryable` outcome for a non-200, non-{400,401} response, attaching
|
|
1114
|
+
* the failed catalog `source` (+ a `detail` carrying the upstream cause) ONLY when
|
|
1115
|
+
* the 5xx body is a real `source_unavailable` SourceError that names a source.
|
|
1116
|
+
*
|
|
1117
|
+
* This is the seam where outcome (a) (sil/network down → bare retryable, generic
|
|
1118
|
+
* copy) and outcome (b) (a named source down → source-named retryable) become
|
|
1119
|
+
* distinguishable — see {@link SearchOutcome}. The gate is the PRESENCE of a real
|
|
1120
|
+
* non-empty-string `source` field on the body, NEVER the `message` prose: a
|
|
1121
|
+
* sil-internal 5xx (no `source`), a bodyless/garbage non-200, or a `source` that is
|
|
1122
|
+
* null/number/empty/object/array all fall back to the bare sourceless retryable.
|
|
1123
|
+
* Attaching a source to a non-source 5xx would re-introduce wrong attribution in
|
|
1124
|
+
* the opposite direction (a sil-down event falsely named as a source outage), so
|
|
1125
|
+
* the populate must never fabricate or coerce.
|
|
1126
|
+
*
|
|
1127
|
+
* `detail` is the upstream cause the consumer can relay — the body's `message`
|
|
1128
|
+
* when present, else its `error` code. It is only set alongside a real `source`
|
|
1129
|
+
* (an outcome-a retryable carries neither field).
|
|
1130
|
+
*/
|
|
1131
|
+
function retryableFromBody(body) {
|
|
1132
|
+
const obj = asRecord(body);
|
|
1133
|
+
const source = obj?.["source"];
|
|
1134
|
+
if (typeof source !== "string" || source.length === 0) {
|
|
1135
|
+
return { kind: "retryable" };
|
|
1136
|
+
}
|
|
1137
|
+
const message = obj?.["message"];
|
|
1138
|
+
const error = obj?.["error"];
|
|
1139
|
+
const detail = typeof message === "string" && message.length > 0
|
|
1140
|
+
? message
|
|
1141
|
+
: typeof error === "string" && error.length > 0
|
|
1142
|
+
? error
|
|
1143
|
+
: source;
|
|
1144
|
+
return { kind: "retryable", source, detail };
|
|
1145
|
+
}
|
|
971
1146
|
/** Pull sil-api's structured `{ error, message }` out of a 400 body, defaulting
|
|
972
1147
|
* each field when the shape is unexpected so the agent always gets an actionable
|
|
973
1148
|
* (if generic) hint rather than `undefined`. */
|
package/dist/tools/catalog.js
CHANGED
|
@@ -53,16 +53,16 @@ import { clearTokens, readTokens } from "../lib/credentials.js";
|
|
|
53
53
|
import { lookupCatalog, refreshAndRetryOnce, searchCatalog, } from "../lib/sil-client.js";
|
|
54
54
|
import { jsonResult } from "../lib/tool-result.js";
|
|
55
55
|
/**
|
|
56
|
-
* The TIGHTENED ship-to
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
56
|
+
* The TIGHTENED ship-to format contract (founder re-spec 2026-06-11), pinned as a
|
|
57
|
+
* `pattern` BOTH the local schema and sil-api's `@sil/schemas` `ShipTo` enforce
|
|
58
|
+
* IDENTICALLY (byte-for-byte) — so the plugin rejects a malformed value client-side
|
|
59
|
+
* instead of forwarding free text and eating an opaque, fail-late sil-api 400. These
|
|
60
|
+
* same patterns are the schema `pattern` (so the host validates) AND the read-site
|
|
61
|
+
* format gate (so a drifted on-disk call is rejected), defined once here to keep the
|
|
62
|
+
* two in lockstep. The sil-services sibling
|
|
63
63
|
* (`attach-buyer-ship-to-context-server-side-in-sil-ap`) MUST mirror these exactly;
|
|
64
64
|
* the sil-stage eval verifies it end-to-end.
|
|
65
|
-
* - country (ships_to
|
|
65
|
+
* - country (ships_to): ISO 3166-1 alpha-2, a 2-letter code.
|
|
66
66
|
* - region: ISO 3166-2 subdivision code (CA/NY/BY/97), bounded — NOT a place name.
|
|
67
67
|
* - postal_code: a single self-contained pattern (a length-cap lookahead 2–12
|
|
68
68
|
* chars, separators counted, + a structural body of alnum runs joined by single
|
|
@@ -84,7 +84,21 @@ function registerSearch(api) {
|
|
|
84
84
|
+ " and/or filters (`category`, `price_min`/`price_max` in the currency's"
|
|
85
85
|
+ " minor units, e.g. cents). Returns a ranked list (best match first —"
|
|
86
86
|
+ " present results in order, do not re-rank), each item a purchasable"
|
|
87
|
-
+ " variant with id, title, price, availability, checkout_url, and source
|
|
87
|
+
+ " variant with id, title, price, availability, checkout_url, and source,"
|
|
88
|
+
+ " plus (where the source provides them) the evaluate-before-buy fields:"
|
|
89
|
+
+ " product and variant `url`, a short `description`, `media`, the product"
|
|
90
|
+
+ " `options` (the menu of choices), the `seller` (with policy/info links),"
|
|
91
|
+
+ " and arbitrary `metadata`. THREE DISTINCT ACTIONS the agent must not"
|
|
92
|
+
+ " conflate: (1) VIEW — a product's or variant's `url` opens the PAGE to"
|
|
93
|
+
+ " view / learn more; hand it to the user to SEE the item, it is NOT a"
|
|
94
|
+
+ " purchase. (2) DIG IN — `seller.links` are the seller's policy / info"
|
|
95
|
+
+ " links (refund policy, shipping policy, terms); follow one to answer"
|
|
96
|
+
+ " \"what's their return policy?\" without a web search. (3) BUY —"
|
|
97
|
+
+ " `checkout_url` is the variant permalink that commits the purchase; use it"
|
|
98
|
+
+ " ONLY to buy. A variant's `url` and its `checkout_url` are DIFFERENT"
|
|
99
|
+
+ " targets: `url` is the page (view / learn more) whereas `checkout_url`"
|
|
100
|
+
+ " buys — never hand back `checkout_url` for a \"show me / learn more\""
|
|
101
|
+
+ " intent, and never stall on `url` when the user said \"buy\"."
|
|
88
102
|
+ " Use the returned `cursor` to fetch the next page (its absence means no"
|
|
89
103
|
+ " more results — never infer end-of-results from the page size). An empty"
|
|
90
104
|
+ " result list means nothing matched (a normal outcome, not an error)."
|
|
@@ -103,12 +117,17 @@ function registerSearch(api) {
|
|
|
103
117
|
+ " code, NOT a country name); `region` (optional) = the ISO 3166-2 subdivision"
|
|
104
118
|
+ " code (CA, NY, BY — a code, NOT a place name); `postal_code` (optional) ="
|
|
105
119
|
+ " the destination postal/ZIP code. The other optional filters need no prior"
|
|
106
|
-
+ " tool call: `
|
|
107
|
-
+ "
|
|
108
|
-
+ " (
|
|
109
|
-
+ " by
|
|
110
|
-
+ "
|
|
111
|
-
+ "
|
|
120
|
+
+ " tool call: `condition` (array; the values are exactly \"new\" or"
|
|
121
|
+
+ " \"secondhand\", lowercase) filters by product condition; `available`"
|
|
122
|
+
+ " (boolean) controls availability — the server returns only sale-ready items"
|
|
123
|
+
+ " by default, so set `available: false` to INCLUDE out-of-stock/unavailable"
|
|
124
|
+
+ " items. `local_merchants` (boolean) is a BEST-EFFORT BIAS toward shops based"
|
|
125
|
+
+ " in the user's OWN country (home-country / domestic / local sellers) — set it"
|
|
126
|
+
+ " ONLY when the shopper asks for local/domestic shops; it nudges local shops up"
|
|
127
|
+
+ " the ranking but does NOT restrict results to them, so never tell the user the"
|
|
128
|
+
+ " results are all local. To actually surface local shops, ALSO issue the"
|
|
129
|
+
+ " `query` in the USER'S LANGUAGE (a Greek-language query surfaces Greek shops);"
|
|
130
|
+
+ " pass NO country — sil resolves it server-side. Requires registration (run"
|
|
112
131
|
+ " sil_register first).",
|
|
113
132
|
parameters: Type.Object({
|
|
114
133
|
query: Type.Optional(Type.String({
|
|
@@ -156,15 +175,20 @@ function registerSearch(api) {
|
|
|
156
175
|
+ " default with a DIFFERENT destination than the registered address."
|
|
157
176
|
+ " Send ISO CODES, never free-text place names.",
|
|
158
177
|
})),
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
+ "
|
|
178
|
+
local_merchants: Type.Optional(Type.Boolean({
|
|
179
|
+
description: "Bias results toward shops based in the USER'S OWN country (home-country"
|
|
180
|
+
+ " / domestic / local sellers) — set true ONLY when the shopper asks for"
|
|
181
|
+
+ " local or domestic shops (e.g. \"buy from a Greek shop\", \"support"
|
|
182
|
+
+ " local businesses\"). This is a BEST-EFFORT BIAS, NOT a filter: it"
|
|
183
|
+
+ " nudges local shops up the ranking but does NOT restrict results to them"
|
|
184
|
+
+ " and does NOT guarantee every result is local — some local shops won't"
|
|
185
|
+
+ " be detected and some non-local shops may still appear, so never tell"
|
|
186
|
+
+ " the user the results are all local sellers. To actually surface local"
|
|
187
|
+
+ " shops, also issue the `query` in the USER'S LANGUAGE (a Greek-language"
|
|
188
|
+
+ " query surfaces Greek shops; an English query will not). You pass NO"
|
|
189
|
+
+ " country — sil resolves the user's country server-side from their"
|
|
190
|
+
+ " registered address, so do NOT call sil_whoami or pass a country. Omit"
|
|
191
|
+
+ " (or false) for the normal unbiased ranking.",
|
|
168
192
|
})),
|
|
169
193
|
condition: Type.Optional(Type.Array(Type.String(), {
|
|
170
194
|
description: "Filter by product condition. The values are exactly \"new\" or"
|
|
@@ -244,12 +268,30 @@ function mapSearchOutcome(api, outcome) {
|
|
|
244
268
|
switch (outcome.kind) {
|
|
245
269
|
case "ok":
|
|
246
270
|
return searchResult(outcome);
|
|
271
|
+
case "forbidden":
|
|
272
|
+
// A 403 surfaces the SAME forbidden envelope `sil_whoami` emits — never the
|
|
273
|
+
// false-transient `retryable`. On `user_not_provisioned` (and ONLY that exact
|
|
274
|
+
// reason) the held token maps to no account on this backend and a refresh
|
|
275
|
+
// cannot help — structurally dead, like the invalid_grant/second_unauthorized
|
|
276
|
+
// clears below — so clear it HERE (the tool call site, never the pure
|
|
277
|
+
// classifier) and the next sil_register re-onboards instead of short-circuiting
|
|
278
|
+
// to already_registered. A `principal_mismatch` / unknown reason can be
|
|
279
|
+
// transient and stays recoverable — it MUST NOT clear (the exact-equality gate
|
|
280
|
+
// is the correctness boundary: a startsWith/truthy check would wrongly wipe a
|
|
281
|
+
// good session).
|
|
282
|
+
api.logger.warn("sil_search_forbidden", { reason: outcome.reason });
|
|
283
|
+
if (outcome.reason === "user_not_provisioned")
|
|
284
|
+
clearTokens();
|
|
285
|
+
return forbidden(outcome.reason);
|
|
247
286
|
case "invalid_request":
|
|
248
287
|
api.logger.info("sil_search_invalid_request", { error: outcome.error });
|
|
249
288
|
return invalidRequest(outcome.error, outcome.message);
|
|
250
289
|
case "retryable":
|
|
251
|
-
|
|
252
|
-
|
|
290
|
+
// A source-attributed 5xx names the failed source (outcome b); a sil/network
|
|
291
|
+
// blip carries no source and stays the generic copy (outcome a). The log marker
|
|
292
|
+
// records the source when present so a flaky source is visible to operators.
|
|
293
|
+
api.logger.info("sil_search_retryable", outcome.source ? { source: outcome.source } : {});
|
|
294
|
+
return transient("sil_search", outcome.source, outcome.detail);
|
|
253
295
|
case "unauthorized":
|
|
254
296
|
return mustReregister("sil_search");
|
|
255
297
|
}
|
|
@@ -304,7 +346,17 @@ function registerProductGet(api) {
|
|
|
304
346
|
+ " Pass `ids` (one or more product/variant ids you already hold, e.g. from"
|
|
305
347
|
+ " a prior sil_search result) and get the matching products back with FRESH"
|
|
306
348
|
+ " detail: each product's description plus its featured purchasable variant"
|
|
307
|
-
+ " (id, title, price, availability, checkout_url, options)
|
|
349
|
+
+ " (id, title, price, availability, checkout_url, options), and — where the"
|
|
350
|
+
+ " source provides them — the same evaluate-before-buy fields sil_search"
|
|
351
|
+
+ " surfaces: product and variant `url`, `media`, the product `options` menu,"
|
|
352
|
+
+ " the `seller` (with policy/info links), and `metadata`. The SAME three"
|
|
353
|
+
+ " distinct actions apply: (1) VIEW — a product's or variant's `url` opens"
|
|
354
|
+
+ " the PAGE to view / learn more (NOT a purchase); (2) DIG IN —"
|
|
355
|
+
+ " `seller.links` follow the seller's policy / info links (refund, shipping,"
|
|
356
|
+
+ " terms); (3) BUY — `checkout_url` is the variant permalink that commits the"
|
|
357
|
+
+ " purchase. A variant's `url` and its `checkout_url` are DIFFERENT targets:"
|
|
358
|
+
+ " `url` is the page (view) whereas `checkout_url` buys — do not conflate"
|
|
359
|
+
+ " them. Re-fetch right"
|
|
308
360
|
+ " before the user buys — prices, availability, and checkout_url are"
|
|
309
361
|
+ " point-in-time, not guarantees. Each variant carries an `inputs` list"
|
|
310
362
|
+ " correlating it back to the id(s) you asked about (the response is NOT in"
|
|
@@ -371,12 +423,24 @@ function mapLookupOutcome(api, outcome) {
|
|
|
371
423
|
switch (outcome.kind) {
|
|
372
424
|
case "ok":
|
|
373
425
|
return lookupResult(outcome);
|
|
426
|
+
case "forbidden":
|
|
427
|
+
// Symmetric with sil_search (one vocabulary, AC2/AC7/AC10): a 403 is the shared
|
|
428
|
+
// forbidden envelope, and `user_not_provisioned` — and ONLY that exact reason —
|
|
429
|
+
// clears the structurally-dead token at this call site so recovery terminates
|
|
430
|
+
// regardless of which catalog tool revealed the state. `principal_mismatch` /
|
|
431
|
+
// unknown reasons survive (recoverable; the same exact-equality gate).
|
|
432
|
+
api.logger.warn("sil_product_get_forbidden", { reason: outcome.reason });
|
|
433
|
+
if (outcome.reason === "user_not_provisioned")
|
|
434
|
+
clearTokens();
|
|
435
|
+
return forbidden(outcome.reason);
|
|
374
436
|
case "invalid_request":
|
|
375
437
|
api.logger.info("sil_product_get_invalid_request", { error: outcome.error });
|
|
376
438
|
return invalidRequest(outcome.error, outcome.message);
|
|
377
439
|
case "retryable":
|
|
378
|
-
|
|
379
|
-
|
|
440
|
+
// Symmetric with sil_search: a source-attributed 5xx names the source (outcome
|
|
441
|
+
// b); a sil/network blip is the generic copy (outcome a). One error vocabulary.
|
|
442
|
+
api.logger.info("sil_product_get_retryable", outcome.source ? { source: outcome.source } : {});
|
|
443
|
+
return transient("sil_product_get", outcome.source, outcome.detail);
|
|
380
444
|
case "unauthorized":
|
|
381
445
|
return mustReregister("sil_product_get");
|
|
382
446
|
}
|
|
@@ -417,20 +481,21 @@ function invalidIds() {
|
|
|
417
481
|
* a drifted on-disk call must not slip a non-string into the query mapping. No
|
|
418
482
|
* `any`, no unchecked `as`.
|
|
419
483
|
*
|
|
420
|
-
* The
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
484
|
+
* The serviceability/localization filters narrow by their own type: `ship_to` to an
|
|
485
|
+
* object with a string `country` (a primitive/number is DROPPED), `condition` to a
|
|
486
|
+
* string[] (a bare string is dropped), `available` and `local_merchants` to a boolean
|
|
487
|
+
* (a string is dropped). The drop is TYPE-driven, never value-driven, so a valid
|
|
488
|
+
* `available: false` survives — it is a boolean, the meaningful "include unavailable
|
|
489
|
+
* items" signal, not a falsy value to discard.
|
|
426
490
|
*
|
|
427
|
-
* Beyond TYPE narrowing, `ship_to
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
*
|
|
491
|
+
* Beyond TYPE narrowing, `ship_to` also FORMAT-validates every provided string field
|
|
492
|
+
* (country alpha-2, region 3166-2, postal bounded) against the shared patterns: a
|
|
493
|
+
* present-but-malformed value returns an `invalid` read so the tool rejects the
|
|
494
|
+
* request client-side with a clear `invalid_filter` error (better agent UX than an
|
|
495
|
+
* opaque, fail-late sil-api 400). `condition` is NOT format-validated — its wire
|
|
496
|
+
* stays OPEN (an unrecognized value still forwards; steering to new/secondhand lives
|
|
497
|
+
* in the description only). `local_merchants` is a plain boolean bias (no format, no
|
|
498
|
+
* country) — its whole steer lives in the description. The first bad field wins. */
|
|
434
499
|
function readSearchParams(params) {
|
|
435
500
|
const result = {};
|
|
436
501
|
const query = params["query"];
|
|
@@ -456,17 +521,20 @@ function readSearchParams(params) {
|
|
|
456
521
|
return { kind: "invalid", field: shipTo.field };
|
|
457
522
|
if (shipTo.kind === "ok")
|
|
458
523
|
result.ship_to = shipTo.value;
|
|
459
|
-
const shipsFrom = readShipsFrom(params["ships_from"]);
|
|
460
|
-
if (shipsFrom.kind === "invalid")
|
|
461
|
-
return { kind: "invalid", field: shipsFrom.field };
|
|
462
|
-
if (shipsFrom.kind === "ok")
|
|
463
|
-
result.ships_from = shipsFrom.value;
|
|
464
524
|
const condition = readCondition(params["condition"]);
|
|
465
525
|
if (condition !== null)
|
|
466
526
|
result.condition = condition;
|
|
467
527
|
const available = params["available"];
|
|
468
528
|
if (typeof available === "boolean")
|
|
469
529
|
result.available = available;
|
|
530
|
+
// `local_merchants` is a plain boolean bias narrowed exactly like `available`:
|
|
531
|
+
// a wrong type is DROPPED (treated as absent), never coerced. A valid `false`
|
|
532
|
+
// survives the read site (type-driven, not value-driven); the omit-when-falsy
|
|
533
|
+
// discipline for the BIAS itself lives at the wire (`buildSearchBody`), since
|
|
534
|
+
// unlike `available:false`, a false bias carries no ranking signal.
|
|
535
|
+
const localMerchants = params["local_merchants"];
|
|
536
|
+
if (typeof localMerchants === "boolean")
|
|
537
|
+
result.local_merchants = localMerchants;
|
|
470
538
|
return { kind: "ok", params: result };
|
|
471
539
|
}
|
|
472
540
|
/** A non-null plain object, or null for anything else (arrays/primitives). */
|
|
@@ -508,22 +576,6 @@ function readShipTo(raw) {
|
|
|
508
576
|
}
|
|
509
577
|
return { kind: "ok", value: result };
|
|
510
578
|
}
|
|
511
|
-
/** Narrow a `ships_from` arg to {@link ShipsFrom}. A non-object/missing-country is
|
|
512
|
-
* `absent` (DROPPED, wrong-TYPE discipline); a provided `country` string that fails
|
|
513
|
-
* the alpha-2 pattern is `invalid` (REJECT). Country is uppercased on the wire, not
|
|
514
|
-
* here. */
|
|
515
|
-
function readShipsFrom(raw) {
|
|
516
|
-
const obj = asRecord(raw);
|
|
517
|
-
if (obj === null)
|
|
518
|
-
return { kind: "absent" };
|
|
519
|
-
const country = obj["country"];
|
|
520
|
-
if (typeof country !== "string" || country.length === 0)
|
|
521
|
-
return { kind: "absent" };
|
|
522
|
-
if (!matchesPattern(country, COUNTRY_PATTERN)) {
|
|
523
|
-
return { kind: "invalid", field: "ships_from.country" };
|
|
524
|
-
}
|
|
525
|
-
return { kind: "ok", value: { country } };
|
|
526
|
-
}
|
|
527
579
|
/** Test a value against one of the shared schema patterns, anchored exactly as the
|
|
528
580
|
* schema's `pattern` is (the constants carry their own `^…$`). A fresh `RegExp` per
|
|
529
581
|
* call keeps the patterns as plain shared strings (the schema needs the string form;
|
|
@@ -619,12 +671,59 @@ function mustReregister(tool) {
|
|
|
619
671
|
recovery: "sil_register",
|
|
620
672
|
});
|
|
621
673
|
}
|
|
622
|
-
/**
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
|
|
674
|
+
/** Terminal-but-distinct: a 403 — the token is valid but the user isn't provisioned
|
|
675
|
+
* (or a principal mismatch / other reason). Refreshing would not help (a 403 is not
|
|
676
|
+
* a 401). Surfaces the SAME envelope `sil_whoami`'s `forbidden()` (identity.ts) emits
|
|
677
|
+
* — `{ status:"forbidden", reason, message, recovery:"sil_register" }`, byte-identical
|
|
678
|
+
* including the reason-driven message branch — so the three sil-api tools speak ONE
|
|
679
|
+
* error vocabulary (AC5). `user_not_provisioned` reads as an actionable onboarding
|
|
680
|
+
* prompt; any other reason is the generic forbidden copy carrying the reason. The
|
|
681
|
+
* recovery hint is always `sil_register` (the message names it, tool-agnostic — the
|
|
682
|
+
* parity with `sil_whoami`'s envelope is byte-exact, so it carries no per-tool name).
|
|
683
|
+
* The dead-token CLEAR is NOT here — it is the caller's decision (gated on
|
|
684
|
+
* `user_not_provisioned`), so a `principal_mismatch` that still wants the legible
|
|
685
|
+
* envelope does not have its token wiped. */
|
|
686
|
+
function forbidden(reason) {
|
|
687
|
+
const message = reason === "user_not_provisioned"
|
|
688
|
+
? "Your sil account is not fully set up. Complete onboarding (run"
|
|
689
|
+
+ " sil_register) and try again."
|
|
690
|
+
: "sil rejected this request (" + reason + "). Run sil_register to"
|
|
691
|
+
+ " re-establish your session, then try again.";
|
|
692
|
+
return jsonResult({ status: "forbidden", reason, message, recovery: "sil_register" });
|
|
693
|
+
}
|
|
694
|
+
/** Transient: a retryable blip — try again, NOT a re-register (a false terminal on
|
|
695
|
+
* a transient would send the agent down a recovery path that can't fix it). The two
|
|
696
|
+
* causally-distinct transient failures share `status: "retryable"` (both succeed on
|
|
697
|
+
* backoff) but split on ATTRIBUTION, which is the whole point of this card:
|
|
698
|
+
*
|
|
699
|
+
* - `source` ABSENT (outcome a) — sil itself / the network / transport is down,
|
|
700
|
+
* OR a refresh-leg blip. The agent retries the same call; the copy stays the
|
|
701
|
+
* GENERIC "sil is temporarily unavailable" and names no source it cannot
|
|
702
|
+
* identify (attribution honesty).
|
|
703
|
+
* - `source` PRESENT (outcome b) — a specific catalog source is down or
|
|
704
|
+
* rate-limited. The copy NAMES that source and must NEVER say "sil is …
|
|
705
|
+
* unavailable" / "sil is down": sil is healthy, one source is degraded, often
|
|
706
|
+
* for seconds, and mis-attributing it to sil makes the agent abandon a working
|
|
707
|
+
* platform. `detail` (the upstream cause) is relayed when present.
|
|
708
|
+
*
|
|
709
|
+
* The source is named ONLY when the wire actually carried it (the classifier gates
|
|
710
|
+
* on a real `source` field — see `retryableFromBody` in sil-client). The named-source
|
|
711
|
+
* copy is SELF-AUTHORED around the source token rather than echoing the raw upstream
|
|
712
|
+
* `detail` prose verbatim — the upstream wording is sil-api's to change and could
|
|
713
|
+
* itself contain "sil is …" phrasing that would muddy the attribution; `detail` is
|
|
714
|
+
* surfaced as a separate, clearly-delimited field instead. The `tool` name keeps the
|
|
715
|
+
* retry guidance actionable; the status taxonomy is shared. */
|
|
716
|
+
function transient(tool, source, detail) {
|
|
717
|
+
if (source === undefined) {
|
|
718
|
+
return jsonResult({
|
|
719
|
+
status: "retryable",
|
|
720
|
+
message: `sil is temporarily unavailable. Please try ${tool} again.`,
|
|
721
|
+
});
|
|
722
|
+
}
|
|
626
723
|
return jsonResult({
|
|
627
724
|
status: "retryable",
|
|
628
|
-
message: `
|
|
725
|
+
message: `The catalog source "${source}" is temporarily unavailable.`
|
|
726
|
+
+ ` sil itself is fine — retry ${tool} shortly.`,
|
|
727
|
+
...(detail !== undefined ? { detail } : {}),
|
|
629
728
|
});
|
|
630
729
|
}
|
package/dist/tools/identity.js
CHANGED
|
@@ -181,7 +181,18 @@ function identityOutcomeToResult(api, outcome) {
|
|
|
181
181
|
case "ok":
|
|
182
182
|
return identityResult(outcome.identity);
|
|
183
183
|
case "forbidden":
|
|
184
|
+
// Decision B — the dead-token clear is UNIFORM across all three sil-api tools.
|
|
185
|
+
// `sil_whoami` is the tool that is legible TODAY; an agent that diagnoses the
|
|
186
|
+
// 403 via whoami, follows `recovery:"sil_register"`, and hits
|
|
187
|
+
// `already_registered` is stranded identically to the catalog path. So clear on
|
|
188
|
+
// `user_not_provisioned` HERE too (the held token maps to no account on this
|
|
189
|
+
// backend; a refresh cannot help — structurally dead, like the invalid_grant
|
|
190
|
+
// clear above). Gated on EXACT equality: `principal_mismatch` / unknown reasons
|
|
191
|
+
// can be transient and must stay recoverable, so they keep the legible forbidden
|
|
192
|
+
// envelope WITHOUT a destructive clear (AC9 clears, AC10 does not).
|
|
184
193
|
api.logger.warn("sil_whoami_forbidden", { reason: outcome.reason });
|
|
194
|
+
if (outcome.reason === "user_not_provisioned")
|
|
195
|
+
clearTokens();
|
|
185
196
|
return forbidden(outcome.reason);
|
|
186
197
|
case "retryable":
|
|
187
198
|
api.logger.info("sil_whoami_retryable", {});
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "sil",
|
|
3
3
|
"name": "sil",
|
|
4
4
|
"description": "sil commerce plugin for OpenClaw — register on sil, read your identity, and search and look up products in the sil catalog.",
|
|
5
|
-
"version": "0.2.
|
|
5
|
+
"version": "0.2.3",
|
|
6
6
|
"skills": ["./skill"],
|
|
7
7
|
"activation": {
|
|
8
8
|
"onCapabilities": ["tool"]
|
package/package.json
CHANGED