sil-openclaw 0.6.0 → 0.8.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/EXAMPLES.md +93 -0
  3. package/README.md +58 -120
  4. package/SECURITY.md +12 -9
  5. package/assets/banner-dark.svg +15 -0
  6. package/assets/banner.svg +15 -0
  7. package/dist/gateway/screen.js +174 -0
  8. package/dist/index.js +5 -9
  9. package/dist/lib/answers.js +59 -0
  10. package/dist/lib/screen-log.js +13 -0
  11. package/dist/lib/shopping-call.js +27 -28
  12. package/dist/lib/sil-client.js +49 -66
  13. package/dist/lib/tool-result.js +1 -1
  14. package/dist/tools/catalog.js +113 -272
  15. package/dist/tools/identity.js +79 -88
  16. package/openclaw.plugin.json +12 -7
  17. package/package.json +4 -2
  18. package/schema/PROVENANCE.md +7 -4
  19. package/schema/shopping-brief-read-request.schema.json +2 -1
  20. package/schema/shopping-brief-read-response.schema.json +98 -50
  21. package/schema/shopping-brief-write-request.schema.json +322 -0
  22. package/schema/{shopping-brief-create-response.schema.json → shopping-brief-write-response.schema.json} +3 -3
  23. package/schema/shopping-content-request.schema.json +12 -31
  24. package/schema/shopping-content-response.schema.json +14 -95
  25. package/schema/shopping-domain-get-request.schema.json +24 -1
  26. package/schema/shopping-domain-get-response.schema.json +23 -421
  27. package/schema/shopping-domain-search-request.schema.json +3 -3
  28. package/schema/shopping-domain-search-response.schema.json +3 -56
  29. package/schema/shopping-offers-request.schema.json +14 -9
  30. package/schema/shopping-offers-response.schema.json +368 -91
  31. package/schema/shopping-product-get-request.schema.json +4 -3
  32. package/schema/shopping-product-get-response.schema.json +347 -46
  33. package/schema/shopping-search-request.schema.json +53 -40
  34. package/schema/shopping-search-response.schema.json +408 -116
  35. package/schema/shopping-seller-get-request.schema.json +13 -1
  36. package/schema/shopping-seller-get-response.schema.json +594 -225
  37. package/schema/shopping-user-forget-request.schema.json +43 -0
  38. package/schema/shopping-user-forget-response.schema.json +74 -0
  39. package/schema/shopping-user-read-request.schema.json +37 -0
  40. package/schema/shopping-user-read-response.schema.json +372 -0
  41. package/schema/shopping-user-remember-request.schema.json +341 -0
  42. package/schema/shopping-user-remember-response.schema.json +66 -0
  43. package/schema/sil-whoami-request.schema.json +8 -0
  44. package/schema/sil-whoami-response.schema.json +99 -0
  45. package/sil-shopping/SKILL.md +149 -208
  46. package/dist/gateway/search-results.js +0 -99
  47. package/dist/lib/search-results-log.js +0 -23
  48. package/dist/lib/search-results-store.js +0 -116
  49. package/schema/shopping-brief-create-request.schema.json +0 -98
  50. package/schema/shopping-brief-edit-request.schema.json +0 -125
  51. package/schema/shopping-brief-edit-response.schema.json +0 -24
  52. package/schema/shopping-profile-edit-request.schema.json +0 -97
  53. package/schema/shopping-profile-edit-response.schema.json +0 -17
@@ -1,7 +1,10 @@
1
1
  import { Type } from "typebox";
2
+ import { keepAnswer } from "../lib/answers.js";
2
3
  import { getWebUrl, getWebUrlSource, getApiUrl } from "../lib/config.js";
3
4
  import { clearTokens, getTokensPath, hasTokens, readConfig, readTokens, writeConfig, writeTokens, } from "../lib/credentials.js";
4
- import { wiringAdvisories } from "../lib/host-wiring.js";
5
+ import { readHostVersion, wiringAdvisories, wiringAdvisoryBlocks } from "../lib/host-wiring.js";
6
+ import { readInstalledVersion } from "../lib/version-advisory.js";
7
+ import { runOf } from "./catalog.js";
5
8
  import { deriveChallenge, newSessionId, newVerifier } from "../lib/pkce.js";
6
9
  import { POLL_DEADLINE_MS, POLL_INTERVAL_MS, startPoll, } from "../lib/poller.js";
7
10
  import { claimSession, fetchIdentity, refreshAndRetryOnce, stripTrailingSlash, } from "../lib/sil-client.js";
@@ -94,85 +97,83 @@ function registerRegister(api) {
94
97
  * result and is never logged; tokens reach neither.
95
98
  */
96
99
  function registerWhoami(api) {
97
- api.registerTool({
98
- name: "sil_whoami",
99
- label: "Who am I on sil",
100
- description: "The buyer's name, country, `gender`, `currency` and the addresses on file, and"
101
- + " the `measurements` and `preferences` sil already holds for them — read live from"
102
- + " sil with the credentials sil_register stored, a stale session token refreshed"
103
- + " once and the read retried. `gender` is `male`, `female` or `other`, and is"
104
- + " absent where the buyer never stated one; on anything worn it is the product"
105
- + " spec `gender` in the registry's own spelling (male → `mens`, female →"
106
- + " `womens`), asked once where this answers none and never inferred. `currency` is"
107
- + " the ISO 4217 code they price in, absent where nothing on file says it: a money"
108
- + " row that means theirs leaves `currency` off — with none on file, it names its"
109
- + " own — and sil converts nothing. Call it at the start of a chat: it"
110
- + " says where the buyer is, what they price in, how they measure and what they"
111
- + " lastingly prefer, and you never ask them for anything it answers."
112
- + " shopping_profile_edit is what writes those last three back. If they are not"
113
- + " registered, or the session is past refreshing, the result names the recovery"
114
- + " (sil_register).",
115
- parameters: Type.Object({}),
116
- async execute() {
117
- // 1 — no tokens on disk is the SAME state for a never-registered buyer and
118
- // for one whose token write failed in this process, so the in-process marker
119
- // is the only thing that tells the two apart.
120
- const stored = readTokens();
121
- if (stored === null) {
122
- const failure = getPersistFailure();
123
- return failure !== null ? persistenceFailed(failure) : notRegistered();
124
- }
125
- // A staging/self-host web origin is legitimate, so it is surfaced and warned
126
- // about, never rejected — a wrong one is then diagnosable before anything 404s.
127
- const webOrigin = getWebUrl();
128
- const webOriginSource = getWebUrlSource();
129
- if (webOriginSource !== "default") {
130
- api.logger.warn("sil_whoami_web_origin_override", {
131
- web_origin: webOrigin,
132
- web_origin_source: webOriginSource,
133
- });
134
- }
135
- const originBlock = {
136
- web_origin: webOrigin,
137
- web_origin_source: webOriginSource,
138
- };
139
- // 2 — read identity; on a 401 refresh-and-retry ONCE, shared with every
140
- // `shopping_*` call so the recovery cannot drift between tools.
141
- const first = await fetchIdentity(getApiUrl(), stored.access_token);
142
- const recovered = await refreshAndRetryOnce(first, (o) => o.kind === "unauthorized", (accessToken) => fetchIdentity(getApiUrl(), accessToken));
143
- switch (recovered.kind) {
144
- case "result":
145
- // Logs-only, never a payload field: a session thrashing through silent
146
- // 401 recoveries is invisible otherwise.
147
- if (recovered.refreshed)
148
- api.logger.info("sil_whoami_refreshed", {});
149
- return identityOutcomeToResult(api, recovered.outcome, originBlock);
150
- case "must_reregister":
151
- // Clear the known-dead pair so its stale presence cannot block the
152
- // sil_register recovery; an empty re-read has nothing to clear.
153
- if (recovered.reason === "invalid_grant")
100
+ const pluginVersion = readInstalledVersion();
101
+ const openclawVersion = readHostVersion(api) ?? undefined;
102
+ api.registerTool((ctx) => {
103
+ const run = runOf(ctx, pluginVersion, openclawVersion);
104
+ return {
105
+ name: "sil_whoami",
106
+ label: "Who am I on sil",
107
+ description: "Who is signed in, where they are and what they price in: `name`, `country`,"
108
+ + " `currency`, `gender`, `language`, each absent where sil holds none, and `addresses`,"
109
+ + " each by its name, the default first; `ship_to` on offers names one. Fast: call it freely, and never ask the buyer for what it answers."
110
+ + " `gender` on anything worn is the product spec `gender` (male → `mens`, female →"
111
+ + " `womens`), asked once where it answers none. If they are not registered, or the"
112
+ + " session is past refreshing, the result names the recovery (sil_register).",
113
+ parameters: Type.Object({}),
114
+ async execute(callId) {
115
+ // 1 — no tokens on disk is the SAME state for a never-registered buyer and
116
+ // for one whose token write failed in this process, so the in-process marker
117
+ // is the only thing that tells the two apart.
118
+ const stored = readTokens();
119
+ if (stored === null) {
120
+ const failure = getPersistFailure();
121
+ return failure !== null ? persistenceFailed(failure) : notRegistered();
122
+ }
123
+ // A staging/self-host web origin is legitimate, so it is warned
124
+ // about, never rejected — a wrong one is then diagnosable before anything 404s.
125
+ const webOrigin = getWebUrl();
126
+ const webOriginSource = getWebUrlSource();
127
+ if (webOriginSource !== "default") {
128
+ api.logger.warn("sil_whoami_web_origin_override", {
129
+ web_origin: webOrigin,
130
+ web_origin_source: webOriginSource,
131
+ });
132
+ }
133
+ // 2 — read identity; on a 401 refresh-and-retry ONCE, shared with every
134
+ // `shopping_*` call so the recovery cannot drift between tools.
135
+ const caller = { ...run, toolCallId: callId };
136
+ const first = await fetchIdentity(getApiUrl(), stored.access_token, caller, 1);
137
+ const recovered = await refreshAndRetryOnce(first, (o) => o.kind === "unauthorized", (accessToken) => fetchIdentity(getApiUrl(), accessToken, caller, 2));
138
+ switch (recovered.kind) {
139
+ case "result":
140
+ // Logs-only, never a payload field: a session thrashing through silent
141
+ // 401 recoveries is invisible otherwise.
142
+ if (recovered.refreshed)
143
+ api.logger.info("sil_whoami_refreshed", {});
144
+ return identityOutcomeToResult(api, recovered.outcome, (body) => keepAnswer(api, callId, run.sessionId, body));
145
+ case "must_reregister":
146
+ // Clear the known-dead pair so its stale presence cannot block the
147
+ // sil_register recovery; an empty re-read has nothing to clear.
148
+ if (recovered.reason === "invalid_grant")
149
+ clearTokens();
150
+ api.logger.info("sil_whoami_must_reregister", { cause: recovered.reason });
151
+ return mustReregister();
152
+ case "second_unauthorized":
153
+ // A freshly-rotated token STILL rejected is structurally dead — terminal,
154
+ // never another refresh. Clear the dead pair.
154
155
  clearTokens();
155
- api.logger.info("sil_whoami_must_reregister", { cause: recovered.reason });
156
- return mustReregister();
157
- case "second_unauthorized":
158
- // A freshly-rotated token STILL rejected is structurally dead — terminal,
159
- // never another refresh. Clear the dead pair.
160
- clearTokens();
161
- api.logger.info("sil_whoami_must_reregister", { cause: "retry_unauthorized" });
162
- return mustReregister();
163
- case "retryable":
164
- api.logger.info("sil_whoami_refresh_retryable", {});
165
- return transient();
166
- }
167
- },
168
- });
156
+ api.logger.info("sil_whoami_must_reregister", { cause: "retry_unauthorized" });
157
+ return mustReregister();
158
+ case "retryable":
159
+ api.logger.info("sil_whoami_refresh_retryable", {});
160
+ return transient();
161
+ }
162
+ },
163
+ };
164
+ }, { name: "sil_whoami" });
169
165
  }
170
- /** Map a non-401 identity outcome to the agent-facing result. The origin block
171
- * rides the SUCCESS payload only — pre-failure diagnosis is its whole point. */
172
- function identityOutcomeToResult(api, outcome, originBlock) {
166
+ /** Map a non-401 identity outcome to the agent-facing result. */
167
+ function identityOutcomeToResult(api, outcome, keep) {
173
168
  switch (outcome.kind) {
174
- case "ok":
175
- return identityResult(api, outcome.identity, originBlock);
169
+ case "ok": {
170
+ const body = { status: "ok", ...outcome.identity };
171
+ keep(body);
172
+ return jsonResult(body, ...wiringAdvisoryBlocks(api));
173
+ }
174
+ case "refused":
175
+ api.logger.info("sil_whoami_refused", {});
176
+ return jsonResult({ status: "invalid_request", message: outcome.message });
176
177
  case "forbidden":
177
178
  // A token that maps to no account is structurally dead, so clear it or the
178
179
  // sil_register recovery answers `already_registered` and strands the buyer.
@@ -190,18 +191,8 @@ function identityOutcomeToResult(api, outcome, originBlock) {
190
191
  return mustReregister();
191
192
  }
192
193
  }
193
- /** Success: `identity` carries the buyer's name, country, gender and currency (each when
194
- * the read has one), addresses, measurements and preferences — no token, no Bearer header. */
195
- function identityResult(api, identity, originBlock) {
196
- return jsonResult({
197
- status: "ok",
198
- identity,
199
- ...originBlock,
200
- ...wiringAdvisories(api),
201
- });
202
- }
203
194
  /** Not registered: a distinct, actionable outcome naming the recovery tool. No
204
- * identity fields (name/addresses) so the agent can't mistake it for a read. */
195
+ * identity fields (name/address) so the agent can't mistake it for a read. */
205
196
  function notRegistered() {
206
197
  return jsonResult({
207
198
  status: "not_registered",
@@ -1,26 +1,31 @@
1
1
  {
2
2
  "id": "sil",
3
3
  "name": "sil",
4
- "description": "Turn your OpenClaw into an expert shopping agent.",
5
- "version": "0.6.0",
6
- "skills": ["./sil-shopping"],
4
+ "description": "The Shopping Interface Layer for personal AI agents. Turn your OpenClaw into an expert shopping agent.",
5
+ "version": "0.8.0",
6
+ "skills": [
7
+ "./sil-shopping"
8
+ ],
7
9
  "activation": {
8
- "onCapabilities": ["tool"],
10
+ "onCapabilities": [
11
+ "tool"
12
+ ],
9
13
  "onStartup": true
10
14
  },
11
15
  "contracts": {
12
16
  "tools": [
13
- "shopping_brief_create",
14
- "shopping_brief_edit",
15
17
  "shopping_brief_read",
18
+ "shopping_brief_write",
16
19
  "shopping_content",
17
20
  "shopping_domain_get",
18
21
  "shopping_domain_search",
19
22
  "shopping_offers",
20
23
  "shopping_product_get",
21
- "shopping_profile_edit",
22
24
  "shopping_search",
23
25
  "shopping_seller_get",
26
+ "shopping_user_forget",
27
+ "shopping_user_read",
28
+ "shopping_user_remember",
24
29
  "sil_doctor",
25
30
  "sil_register",
26
31
  "sil_whoami"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sil-openclaw",
3
- "version": "0.6.0",
4
- "description": "Turn your OpenClaw into an expert shopping agent.",
3
+ "version": "0.8.0",
4
+ "description": "The Shopping Interface Layer for personal AI agents. Turn your OpenClaw into an expert shopping agent.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
@@ -34,8 +34,10 @@
34
34
  "schema",
35
35
  "scripts/allowlist-openclaw.mjs",
36
36
  "sil-shopping",
37
+ "assets",
37
38
  "openclaw.plugin.json",
38
39
  "README.md",
40
+ "EXAMPLES.md",
39
41
  "CHANGELOG.md",
40
42
  "SECURITY.md",
41
43
  "LICENSE",
@@ -1,15 +1,18 @@
1
- # Where these twenty-two files come from
1
+ # Where these twenty-six files come from
2
2
 
3
3
  Copied verbatim from `sil-services` `packages/schemas/schema/`, commit
4
- `11ef83e34f413bbd59f277348740c000c19d578a`. One request and one response artifact per
5
- shopping tool; each is `JSON.stringify` of the TypeBox object the API serialises against.
4
+ `fd37ffed3c04ef12c81b3490a91d6dfd290105c3`. One request and one response artifact per
5
+ `shopping_*` tool, plus `sil-whoami-*`; each is `JSON.stringify` of the TypeBox object the
6
+ API serialises against.
6
7
 
7
8
  **Re-copy, never hand-edit.** A local edit is drift the moment the sibling moves, and the
8
9
  plugin registers these bytes as each tool's `parameters` — an edited artifact is a
9
10
  contract the API never agreed to.
10
11
 
11
12
  ```sh
12
- cp <sil-services>/packages/schemas/schema/shopping-*.schema.json schema/
13
+ S=<sil-services>/packages/schemas/schema; rm schema/*.schema.json \
14
+ && cp $S/shopping-*.schema.json $S/sil-whoami-*.schema.json schema/ \
15
+ && node scripts/contract-examples.mjs $S/agent-contract.md
13
16
  ```
14
17
 
15
18
  Byte-identity against the sibling is graded by sil-stage, not here.
@@ -11,5 +11,6 @@
11
11
  "description": "Reads this brief whole; without it, the list of the buyer's briefs comes back."
12
12
  }
13
13
  },
14
- "additionalProperties": false
14
+ "additionalProperties": false,
15
+ "description": "Money is in the minor unit: €130 is 13000."
15
16
  }
@@ -63,66 +63,114 @@
63
63
  "^.*$": {
64
64
  "type": "array",
65
65
  "items": {
66
- "type": "object",
67
- "required": [
68
- "key",
69
- "op",
70
- "value"
71
- ],
72
- "properties": {
73
- "key": {
74
- "type": "string",
75
- "minLength": 1,
76
- "maxLength": 64,
77
- "description": "Names the key from the domain read; `price` is a key every domain has."
78
- },
79
- "op": {
80
- "anyOf": [
81
- {
66
+ "anyOf": [
67
+ {
68
+ "type": "object",
69
+ "required": [
70
+ "spec",
71
+ "op",
72
+ "value"
73
+ ],
74
+ "properties": {
75
+ "spec": {
82
76
  "type": "string",
83
- "const": "eq"
77
+ "minLength": 1,
78
+ "maxLength": 64,
79
+ "description": "Sends a spec the domain read listed, unchanged: a part’s by its path (`boiler.boilerVolume`)."
84
80
  },
85
- {
86
- "type": "string",
87
- "const": "neq"
81
+ "op": {
82
+ "anyOf": [
83
+ {
84
+ "type": "string",
85
+ "const": "eq"
86
+ },
87
+ {
88
+ "type": "string",
89
+ "const": "neq"
90
+ },
91
+ {
92
+ "type": "string",
93
+ "const": "gte"
94
+ },
95
+ {
96
+ "type": "string",
97
+ "const": "lte"
98
+ },
99
+ {
100
+ "type": "string",
101
+ "const": "in"
102
+ },
103
+ {
104
+ "type": "string",
105
+ "const": "nin"
106
+ }
107
+ ],
108
+ "description": "Sends the operator the domain read listed for this spec."
88
109
  },
89
- {
90
- "type": "string",
91
- "const": "gte"
110
+ "value": {
111
+ "description": "Sends the desired value, typed by the spec's type."
92
112
  },
93
- {
113
+ "reason": {
94
114
  "type": "string",
95
- "const": "lte"
96
- },
97
- {
115
+ "minLength": 1,
116
+ "maxLength": 256,
117
+ "description": "Quotes the buyer's own words behind the spec, in English — translated, never a paraphrase, never a sentence they did not say; a spec derived from a measurement quotes the measurement. Reads them back before proposing to relax it."
118
+ }
119
+ },
120
+ "additionalProperties": false
121
+ },
122
+ {
123
+ "type": "object",
124
+ "required": [
125
+ "spec",
126
+ "range"
127
+ ],
128
+ "properties": {
129
+ "spec": {
98
130
  "type": "string",
99
- "const": "in"
131
+ "minLength": 1,
132
+ "maxLength": 64,
133
+ "description": "Names a money spec: `price`, or a seller’s money spec."
134
+ },
135
+ "range": {
136
+ "type": "object",
137
+ "required": [
138
+ "currency"
139
+ ],
140
+ "properties": {
141
+ "min": {
142
+ "type": "integer",
143
+ "minimum": 0,
144
+ "maximum": 9007199254740991,
145
+ "description": "The low end, in the minor unit."
146
+ },
147
+ "max": {
148
+ "type": "integer",
149
+ "minimum": 0,
150
+ "maximum": 9007199254740991,
151
+ "description": "The high end, in the minor unit."
152
+ },
153
+ "currency": {
154
+ "type": "string",
155
+ "pattern": "^[A-Z]{3}$",
156
+ "minLength": 3,
157
+ "maxLength": 3,
158
+ "description": "Both ends in this currency; sil converts nothing."
159
+ }
160
+ },
161
+ "additionalProperties": false,
162
+ "description": "Holds the money spec’s range, one or both ends."
100
163
  },
101
- {
164
+ "reason": {
102
165
  "type": "string",
103
- "const": "nin"
166
+ "minLength": 1,
167
+ "maxLength": 256,
168
+ "description": "Quotes the buyer's own words behind the spec, in English — translated, never a paraphrase, never a sentence they did not say; a spec derived from a measurement quotes the measurement. Reads them back before proposing to relax it."
104
169
  }
105
- ],
106
- "description": "Sends the operator the domain read listed for this key."
107
- },
108
- "value": {
109
- "description": "Sends the desired value, typed by the key's type."
110
- },
111
- "currency": {
112
- "type": "string",
113
- "pattern": "^[A-Z]{3}$",
114
- "minLength": 3,
115
- "maxLength": 3,
116
- "description": "On money, the currency the bound is tested in: sil holds no exchange rate, so it is tested against offers in this currency only. Leave it out to mean the buyer's own currency, as `sil_whoami` answers it."
117
- },
118
- "reason": {
119
- "type": "string",
120
- "minLength": 1,
121
- "maxLength": 256,
122
- "description": "Quotes the buyer's own words behind the spec, in English — translated, never a paraphrase, never a sentence they did not say; a spec derived from a measurement quotes the measurement. Reads them back before proposing to relax it."
170
+ },
171
+ "additionalProperties": false
123
172
  }
124
- },
125
- "additionalProperties": false
173
+ ]
126
174
  }
127
175
  }
128
176
  },