sil-openclaw 0.7.0 → 0.8.1
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 +36 -0
- package/EXAMPLES.md +93 -0
- package/README.md +50 -113
- package/SECURITY.md +9 -6
- package/assets/banner-dark.svg +15 -0
- package/assets/banner.svg +15 -0
- package/dist/gateway/screen.js +174 -0
- package/dist/index.js +5 -9
- package/dist/lib/answers.js +59 -0
- package/dist/lib/screen-log.js +13 -0
- package/dist/lib/shopping-call.js +23 -28
- package/dist/lib/sil-client.js +19 -8
- package/dist/tools/catalog.js +69 -72
- package/dist/tools/identity.js +10 -6
- package/openclaw.plugin.json +2 -2
- package/package.json +4 -2
- package/schema/PROVENANCE.md +1 -1
- package/schema/shopping-brief-read-request.schema.json +2 -1
- package/schema/shopping-brief-read-response.schema.json +98 -50
- package/schema/shopping-brief-write-request.schema.json +202 -105
- package/schema/shopping-content-request.schema.json +12 -28
- package/schema/shopping-content-response.schema.json +49 -256
- package/schema/shopping-domain-get-request.schema.json +16 -11
- package/schema/shopping-domain-get-response.schema.json +24 -460
- package/schema/shopping-domain-search-request.schema.json +3 -3
- package/schema/shopping-domain-search-response.schema.json +3 -56
- package/schema/shopping-offers-request.schema.json +28 -174
- package/schema/shopping-offers-response.schema.json +369 -102
- package/schema/shopping-product-get-request.schema.json +3 -2
- package/schema/shopping-product-get-response.schema.json +332 -128
- package/schema/shopping-search-request.schema.json +41 -19
- package/schema/shopping-search-response.schema.json +405 -187
- package/schema/shopping-seller-get-request.schema.json +13 -1
- package/schema/shopping-seller-get-response.schema.json +488 -147
- package/schema/shopping-user-read-request.schema.json +2 -1
- package/schema/shopping-user-read-response.schema.json +2 -2
- package/schema/shopping-user-remember-request.schema.json +9 -8
- package/schema/sil-whoami-response.schema.json +37 -28
- package/sil-shopping/SKILL.md +132 -137
- package/dist/gateway/search-results.js +0 -99
- package/dist/lib/search-results-log.js +0 -23
- package/dist/lib/search-results-store.js +0 -116
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every `ok` answer a sil tool gave the agent, kept for the paired screen to read back by
|
|
3
|
+
* the host's `callId` (`sil.answer`). In memory and evicted lazily on write: `register()`
|
|
4
|
+
* opens no timer, and nothing of the buyer's rests on disk.
|
|
5
|
+
*/
|
|
6
|
+
import { hasTokens, readConfig } from "./credentials.js";
|
|
7
|
+
import { logScreen } from "./screen-log.js";
|
|
8
|
+
/** A run reads about fifteen answers; prices are point-in-time, so they never outlive this. */
|
|
9
|
+
const RETENTION_MS = 15 * 60_000;
|
|
10
|
+
const MAX_ANSWERS = 64;
|
|
11
|
+
const answers = new Map();
|
|
12
|
+
/** The sil account holding a LIVE session: sign-out unlinks the tokens and keeps the config. */
|
|
13
|
+
export function signedInPrincipal() {
|
|
14
|
+
const id = hasTokens() ? readConfig()?.user?.id : undefined;
|
|
15
|
+
return id === undefined || id.length === 0 ? undefined : id;
|
|
16
|
+
}
|
|
17
|
+
/** A side effect of a tool's `ok` path; the agent's result is unchanged. */
|
|
18
|
+
export function keepAnswer(api, callId, sessionId, body) {
|
|
19
|
+
const principal = signedInPrincipal();
|
|
20
|
+
if (principal === undefined) {
|
|
21
|
+
logScreen(api, "info", "answer_skipped", { callId, reason: "no_principal" });
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const now = Date.now();
|
|
25
|
+
// Map order is age: a re-kept callId must move to the newest end.
|
|
26
|
+
answers.delete(callId);
|
|
27
|
+
for (const [id, kept] of answers)
|
|
28
|
+
if (kept.expiresAtMs <= now)
|
|
29
|
+
answers.delete(id);
|
|
30
|
+
while (answers.size >= MAX_ANSWERS) {
|
|
31
|
+
const oldest = answers.keys().next();
|
|
32
|
+
if (oldest.done === true)
|
|
33
|
+
break;
|
|
34
|
+
answers.delete(oldest.value);
|
|
35
|
+
}
|
|
36
|
+
answers.set(callId, { principal, sessionId, body, expiresAtMs: now + RETENTION_MS });
|
|
37
|
+
}
|
|
38
|
+
/** Pure: a read never evicts or consumes, so a screen reload re-reads the same answer. */
|
|
39
|
+
export function readAnswer(callId, principal) {
|
|
40
|
+
const kept = answers.get(callId);
|
|
41
|
+
if (kept === undefined)
|
|
42
|
+
return { miss: "unknown" };
|
|
43
|
+
if (kept.expiresAtMs <= Date.now())
|
|
44
|
+
return { miss: "expired" };
|
|
45
|
+
if (kept.principal !== principal)
|
|
46
|
+
return { miss: "principal_mismatch" };
|
|
47
|
+
return { body: kept.body };
|
|
48
|
+
}
|
|
49
|
+
/** The conversation of the principal's latest agent call — what the screen is showing. */
|
|
50
|
+
export function latestSession(principal) {
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
let latest;
|
|
53
|
+
for (const kept of answers.values()) {
|
|
54
|
+
if (kept.principal === principal && kept.expiresAtMs > now && kept.sessionId !== undefined) {
|
|
55
|
+
latest = kept.sessionId;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return latest;
|
|
59
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `sil_screen_*` operator markers. Fields repeat INLINE in the message: the host hands
|
|
3
|
+
* the structured object to the log file only, and the console line is the message alone.
|
|
4
|
+
*/
|
|
5
|
+
const MAX_FIELD_CHARS = 128;
|
|
6
|
+
/** Ids come from the screen: a raw newline would forge a second marker line. */
|
|
7
|
+
const render = (value) => String(value)
|
|
8
|
+
.replace(/[^\x21-\x7E]/g, "_")
|
|
9
|
+
.slice(0, MAX_FIELD_CHARS);
|
|
10
|
+
export function logScreen(api, severity, event, fields) {
|
|
11
|
+
const pairs = Object.entries(fields).map(([key, value]) => `${key}=${render(value)}`);
|
|
12
|
+
api.logger[severity](`sil_screen_${event} ${pairs.join(" ")}`, fields);
|
|
13
|
+
}
|
|
@@ -6,16 +6,15 @@
|
|
|
6
6
|
import { getApiUrl } from "./config.js";
|
|
7
7
|
import { clearTokens, readTokens } from "./credentials.js";
|
|
8
8
|
import { callShopping, refreshAndRetryOnce, } from "./sil-client.js";
|
|
9
|
-
import { jsonResult } from "./tool-result.js";
|
|
10
9
|
/** The guide read, as one route constant: two spellings of one path is a route nobody
|
|
11
10
|
* owns. */
|
|
12
11
|
export const DOMAIN_GET_ROUTE = {
|
|
13
12
|
method: "GET",
|
|
14
13
|
path: "/catalog/domains/:path",
|
|
15
|
-
query: ["
|
|
14
|
+
query: ["query", "spec_keywords", "page"],
|
|
16
15
|
};
|
|
17
|
-
function refused(
|
|
18
|
-
return { kind: "refused",
|
|
16
|
+
function refused(body) {
|
|
17
|
+
return { kind: "refused", body };
|
|
19
18
|
}
|
|
20
19
|
/**
|
|
21
20
|
* Call one route with the stored credentials, refreshing and retrying at most once.
|
|
@@ -25,7 +24,7 @@ function refused(status, result) {
|
|
|
25
24
|
export async function callRoute(api, call, args, caller) {
|
|
26
25
|
const stored = readTokens();
|
|
27
26
|
if (stored === null)
|
|
28
|
-
return refused(
|
|
27
|
+
return refused(notRegistered(call.name));
|
|
29
28
|
const first = await callShopping(getApiUrl(), stored.access_token, call, args, caller, 1);
|
|
30
29
|
const recovered = await refreshAndRetryOnce(first, (o) => o.kind === "unauthorized", (accessToken) => callShopping(getApiUrl(), accessToken, call, args, caller, 2));
|
|
31
30
|
switch (recovered.kind) {
|
|
@@ -37,14 +36,14 @@ export async function callRoute(api, call, args, caller) {
|
|
|
37
36
|
if (recovered.reason === "invalid_grant")
|
|
38
37
|
clearTokens();
|
|
39
38
|
api.logger.info(`${call.name}_must_reregister`, { cause: recovered.reason });
|
|
40
|
-
return refused(
|
|
39
|
+
return refused(mustReregister(call.name));
|
|
41
40
|
case "second_unauthorized":
|
|
42
41
|
clearTokens();
|
|
43
42
|
api.logger.info(`${call.name}_must_reregister`, { cause: "retry_unauthorized" });
|
|
44
|
-
return refused(
|
|
43
|
+
return refused(mustReregister(call.name));
|
|
45
44
|
case "retryable":
|
|
46
45
|
api.logger.info(`${call.name}_refresh_retryable`, {});
|
|
47
|
-
return refused(
|
|
46
|
+
return refused(transient(call.name));
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
49
|
function mapOutcome(api, call, outcome) {
|
|
@@ -53,29 +52,29 @@ function mapOutcome(api, call, outcome) {
|
|
|
53
52
|
return { kind: "ok", body: outcome.body };
|
|
54
53
|
case "invalid_request":
|
|
55
54
|
api.logger.info(`${call.name}_invalid_request`, {});
|
|
56
|
-
return refused(
|
|
55
|
+
return refused(refusal("invalid_request", outcome.message));
|
|
57
56
|
case "not_found":
|
|
58
57
|
api.logger.info(`${call.name}_not_found`, {});
|
|
59
|
-
return refused(
|
|
58
|
+
return refused(refusal("not_found", outcome.message, call.recovery?.not_found));
|
|
60
59
|
case "forbidden":
|
|
61
|
-
return refused(
|
|
60
|
+
return refused(forbiddenResult(api, call.name, outcome.reason));
|
|
62
61
|
case "retryable":
|
|
63
62
|
api.logger.info(`${call.name}_retryable`, outcome.source ? { source: outcome.source } : {});
|
|
64
|
-
return refused(
|
|
63
|
+
return refused(transient(call.name, outcome.source, outcome.detail));
|
|
65
64
|
case "unauthorized":
|
|
66
65
|
// Structurally unreachable past the 401 choreography, kept exhaustive so a
|
|
67
66
|
// refactor cannot silently drop a variant.
|
|
68
|
-
return refused(
|
|
67
|
+
return refused(mustReregister(call.name));
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
70
|
/** Not registered: a distinct, actionable outcome naming the recovery tool, with
|
|
72
71
|
* no results field the agent could mistake for an empty answer. */
|
|
73
72
|
function notRegistered(tool) {
|
|
74
|
-
return
|
|
73
|
+
return {
|
|
75
74
|
status: "not_registered",
|
|
76
75
|
message: `Not registered on sil. Run sil_register to authenticate, then call ${tool} again.`,
|
|
77
76
|
recovery: "sil_register",
|
|
78
|
-
}
|
|
77
|
+
};
|
|
79
78
|
}
|
|
80
79
|
/**
|
|
81
80
|
* A refusal the route made before it spent, surfaced VERBATIM: the message names the
|
|
@@ -85,20 +84,16 @@ function notRegistered(tool) {
|
|
|
85
84
|
* one: a next call that fits one of its causes is a hint that misleads on the rest.
|
|
86
85
|
*/
|
|
87
86
|
function refusal(status, message, recovery) {
|
|
88
|
-
return
|
|
89
|
-
status,
|
|
90
|
-
message,
|
|
91
|
-
...(recovery !== undefined ? { recovery } : {}),
|
|
92
|
-
});
|
|
87
|
+
return { status, message, ...(recovery !== undefined ? { recovery } : {}) };
|
|
93
88
|
}
|
|
94
89
|
/** Terminal: the session is dead — reached only after the shared refresh-and-retry
|
|
95
90
|
* choreography has exhausted its one refresh + one retry. */
|
|
96
91
|
function mustReregister(tool) {
|
|
97
|
-
return
|
|
92
|
+
return {
|
|
98
93
|
status: "must_reregister",
|
|
99
94
|
message: `Your sil session has expired. Run sil_register to sign in again, then call ${tool} again.`,
|
|
100
95
|
recovery: "sil_register",
|
|
101
|
-
}
|
|
96
|
+
};
|
|
102
97
|
}
|
|
103
98
|
/**
|
|
104
99
|
* A 403 — the token is valid but the user is not provisioned (or a principal
|
|
@@ -119,7 +114,7 @@ function forbiddenResult(api, tool, reason) {
|
|
|
119
114
|
+ " sil_register) and try again."
|
|
120
115
|
: "sil rejected this request (" + reason + "). Run sil_register to"
|
|
121
116
|
+ " re-establish your session, then try again.";
|
|
122
|
-
return
|
|
117
|
+
return { status: "forbidden", reason, message, recovery: "sil_register" };
|
|
123
118
|
}
|
|
124
119
|
/**
|
|
125
120
|
* Transient: retry, NOT a re-register (a false terminal on a transient sends the
|
|
@@ -130,17 +125,17 @@ function forbiddenResult(api, tool, reason) {
|
|
|
130
125
|
* the copy must never say "sil is unavailable". `detail` (the upstream cause) is
|
|
131
126
|
* relayed as its own field rather than folded into our sentence.
|
|
132
127
|
*/
|
|
133
|
-
|
|
128
|
+
function transient(tool, source, detail) {
|
|
134
129
|
if (source === undefined) {
|
|
135
|
-
return
|
|
130
|
+
return {
|
|
136
131
|
status: "retryable",
|
|
137
132
|
message: `sil is temporarily unavailable. Please try ${tool} again.`,
|
|
138
|
-
}
|
|
133
|
+
};
|
|
139
134
|
}
|
|
140
|
-
return
|
|
135
|
+
return {
|
|
141
136
|
status: "retryable",
|
|
142
137
|
message: `The catalog source "${source}" is temporarily unavailable.`
|
|
143
138
|
+ ` sil itself is fine — retry ${tool} shortly.`,
|
|
144
139
|
...(detail !== undefined ? { detail } : {}),
|
|
145
|
-
}
|
|
140
|
+
};
|
|
146
141
|
}
|
package/dist/lib/sil-client.js
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
* request body:
|
|
37
37
|
*
|
|
38
38
|
* GET <silApiUrl>/identity Authorization: Bearer <access_token>
|
|
39
|
-
* 200 { status, name, country?, currency?, gender?, language?,
|
|
39
|
+
* 200 { status, name, country?, currency?, gender?, language?, addresses } → ok
|
|
40
40
|
* 401 → unauthorized (→ refresh)
|
|
41
41
|
* 403 { error: user_not_provisioned | principal_mismatch } → forbidden (terminal)
|
|
42
42
|
* 426 plugin older than sil accepts → refused (carries sil's message)
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
* The VERB is load-bearing: only `GET /identity` is the self-read — `POST` is the
|
|
65
65
|
* agent enrich route and carries no name. The identity rides in the envelope's
|
|
66
66
|
* `result`, and a 200 with no usable identity (no `name`) falls to `retryable`,
|
|
67
|
-
* never to a false `ok`. A buyer with no
|
|
67
|
+
* never to a false `ok`. A buyer with no address on file is a valid identity.
|
|
68
68
|
*
|
|
69
69
|
* Tokens never appear in a log line here (mirrors sil-web's invariant) — they
|
|
70
70
|
* only travel inside the returned union variant.
|
|
@@ -322,7 +322,7 @@ function callerHeaders(caller, attempt) {
|
|
|
322
322
|
* Both halves are encoded, never concatenated: a dotted registry path is one PATH
|
|
323
323
|
* SEGMENT (a stray `/` in it would re-route the call), and an unencoded query value
|
|
324
324
|
* could inject a second parameter. Only the keys the agent actually sent travel — an
|
|
325
|
-
* empty `
|
|
325
|
+
* empty `query=` is a DIFFERENT request from an omitted `query`, and each gets its own refusal
|
|
326
326
|
* message, which is the agent's whole recourse.
|
|
327
327
|
*/
|
|
328
328
|
function routePath(route, args) {
|
|
@@ -342,8 +342,8 @@ function routePath(route, args) {
|
|
|
342
342
|
const query = new URLSearchParams();
|
|
343
343
|
for (const key of route.query ?? []) {
|
|
344
344
|
const value = args[key];
|
|
345
|
-
if (typeof value === "string")
|
|
346
|
-
query.set(key, value);
|
|
345
|
+
if (typeof value === "string" || typeof value === "number")
|
|
346
|
+
query.set(key, String(value));
|
|
347
347
|
else if (Array.isArray(value)) {
|
|
348
348
|
for (const item of value)
|
|
349
349
|
if (typeof item === "string")
|
|
@@ -363,7 +363,16 @@ function routePath(route, args) {
|
|
|
363
363
|
* "must re-register" signal and DO NOT rotate (a rejected refresh must never be
|
|
364
364
|
* presented as a fresh, valid pair). A 5xx / network blip is retryable.
|
|
365
365
|
*/
|
|
366
|
-
export
|
|
366
|
+
export function refreshStoredTokens() {
|
|
367
|
+
// Single-flight: sil-web rotates the refresh token, so a second exchange of the same one
|
|
368
|
+
// answers invalid_grant and its caller clears a live session.
|
|
369
|
+
refreshing ??= rotateStoredTokens().finally(() => {
|
|
370
|
+
refreshing = null;
|
|
371
|
+
});
|
|
372
|
+
return refreshing;
|
|
373
|
+
}
|
|
374
|
+
let refreshing = null;
|
|
375
|
+
async function rotateStoredTokens() {
|
|
367
376
|
const stored = readTokens();
|
|
368
377
|
if (stored === null) {
|
|
369
378
|
return { status: "must_reregister", reason: "no_stored_tokens" };
|
|
@@ -458,7 +467,9 @@ function extractIdentity(body) {
|
|
|
458
467
|
return null;
|
|
459
468
|
// Optional fields pass through only as the right shape — an absent or malformed one is
|
|
460
469
|
// dropped, never coerced. The VALUES are the route's to decide.
|
|
461
|
-
const
|
|
470
|
+
const addresses = Array.isArray(source["addresses"])
|
|
471
|
+
? source["addresses"].flatMap((one) => asRecord(one) ?? [])
|
|
472
|
+
: [];
|
|
462
473
|
const optional = (key) => typeof source[key] === "string" ? { [key]: source[key] } : {};
|
|
463
474
|
return {
|
|
464
475
|
name,
|
|
@@ -466,7 +477,7 @@ function extractIdentity(body) {
|
|
|
466
477
|
...optional("gender"),
|
|
467
478
|
...optional("currency"),
|
|
468
479
|
...optional("language"),
|
|
469
|
-
|
|
480
|
+
addresses: addresses,
|
|
470
481
|
};
|
|
471
482
|
}
|
|
472
483
|
/** Pull the actionable reason out of a 403 body (`user_not_provisioned` /
|
package/dist/tools/catalog.js
CHANGED
|
@@ -1,44 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The twelve `shopping_*` tools, 1:1 with the sil-api user, brief and catalog routes.
|
|
3
|
-
* Bodies cross verbatim:
|
|
4
|
-
* computed from (`fit`, `unknown`, `variants`) while looking healthy.
|
|
3
|
+
* Bodies cross verbatim: sil's answer is the agent's answer, and the screen's.
|
|
5
4
|
*/
|
|
5
|
+
import { keepAnswer } from "../lib/answers.js";
|
|
6
6
|
import { requestSchema } from "../lib/artifacts.js";
|
|
7
|
-
import { readConfig } from "../lib/credentials.js";
|
|
8
7
|
import { readHostVersion, wiringAdvisoryBlocks } from "../lib/host-wiring.js";
|
|
9
|
-
import { logSearchResults } from "../lib/search-results-log.js";
|
|
10
|
-
import { putSearchResult } from "../lib/search-results-store.js";
|
|
11
8
|
import { DOMAIN_GET_ROUTE, callRoute } from "../lib/shopping-call.js";
|
|
12
9
|
import { jsonResult } from "../lib/tool-result.js";
|
|
13
10
|
import { readInstalledVersion } from "../lib/version-advisory.js";
|
|
14
|
-
/** The tool whose page a paired client can pull back by `callId`. */
|
|
15
|
-
const SEARCH_TOOL = "shopping_search";
|
|
16
11
|
export const SHOPPING_TOOLS = [
|
|
17
12
|
{
|
|
18
13
|
name: "shopping_user_read",
|
|
19
14
|
method: "POST",
|
|
20
15
|
path: "/user/read",
|
|
21
16
|
label: "Read what sil keeps about the buyer",
|
|
22
|
-
description: "
|
|
23
|
-
+ "
|
|
24
|
-
+ "
|
|
17
|
+
description: "Know the buyer: everything kept about them is here, never in your own memory files."
|
|
18
|
+
+ " Read once per conversation before asking anything, when they ask what you keep, and"
|
|
19
|
+
+ " before a forget. A price row is `value` with `unit` its currency; money is in the"
|
|
20
|
+
+ " minor unit: €130 is 13000.",
|
|
25
21
|
},
|
|
26
22
|
{
|
|
27
23
|
name: "shopping_user_remember",
|
|
28
24
|
method: "POST",
|
|
29
25
|
path: "/user/remember",
|
|
30
26
|
label: "Keep what lasts about the buyer",
|
|
31
|
-
description: "Keep what
|
|
32
|
-
+ "
|
|
33
|
-
+ "
|
|
27
|
+
description: "Keep what will matter next time about the buyer (how they use it, what they value, a"
|
|
28
|
+
+ " cap for this kind of thing, a measurement) in the turn you learn it, before any"
|
|
29
|
+
+ " search, and say so with the undo. This is the only place the buyer is kept: \"remember"
|
|
30
|
+
+ " this\" means this call, not a note or memory file. A one-off wish for this buy rides on"
|
|
31
|
+
+ " its calls instead. Each row's `place` is the `name` of the kind you are shopping, from"
|
|
32
|
+
+ " the domain read. A price is `value` with `unit` its currency; money is in the minor"
|
|
33
|
+
+ " unit: €130 is 13000.",
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
name: "shopping_user_forget",
|
|
37
37
|
method: "POST",
|
|
38
38
|
path: "/user/forget",
|
|
39
39
|
label: "Erase what sil keeps, on the buyer's word",
|
|
40
|
-
description: "Erase
|
|
41
|
-
+ " buyer saying yes. The answer states what went and what sil cannot reach.",
|
|
40
|
+
description: "Erase what sil keeps, only after saying what goes and the buyer saying yes.",
|
|
42
41
|
},
|
|
43
42
|
{
|
|
44
43
|
name: "shopping_brief_write",
|
|
@@ -46,79 +45,102 @@ export const SHOPPING_TOOLS = [
|
|
|
46
45
|
path: "/briefs/write",
|
|
47
46
|
label: "Open or update a brief",
|
|
48
47
|
recovery: { not_found: "shopping_brief_read" },
|
|
49
|
-
description: "Write
|
|
50
|
-
+ "
|
|
51
|
-
+ "
|
|
48
|
+
description: "Write down a buy that spans asks or conversations; no other call needs one. Spec rows"
|
|
49
|
+
+ " are `{ spec, op, value }`, a money row `{ spec: \"price\", range: { min?, max?, currency"
|
|
50
|
+
+ " } }`; money is in the minor unit: €130 is 13000.",
|
|
52
51
|
},
|
|
53
52
|
{
|
|
54
53
|
name: "shopping_brief_read",
|
|
55
54
|
method: "POST",
|
|
56
55
|
path: "/briefs/read",
|
|
57
56
|
label: "Read a brief, or list the buyer's briefs",
|
|
58
|
-
description: "Pick a buy up again
|
|
59
|
-
+ " newest first.",
|
|
57
|
+
description: "Pick a written-down buy up again; money is in the minor unit: €130 is 13000.",
|
|
60
58
|
},
|
|
61
59
|
{
|
|
62
60
|
name: "shopping_domain_search",
|
|
63
61
|
method: "GET",
|
|
64
62
|
path: "/catalog/domains",
|
|
65
|
-
query: ["
|
|
66
|
-
label: "
|
|
67
|
-
description: "Place
|
|
68
|
-
+ " could be, best first. An empty answer means sil does not carry it yet.",
|
|
63
|
+
query: ["query"],
|
|
64
|
+
label: "Place the thing",
|
|
65
|
+
description: "Place the thing the buyer named: the leaves sil holds for it.",
|
|
69
66
|
},
|
|
70
67
|
{
|
|
71
68
|
name: "shopping_domain_get",
|
|
72
69
|
...DOMAIN_GET_ROUTE,
|
|
73
|
-
label: "Read a place
|
|
70
|
+
label: "Read how to search a place",
|
|
74
71
|
recovery: { not_found: "shopping_domain_search" },
|
|
75
|
-
description: "
|
|
76
|
-
+ "
|
|
77
|
-
+ "
|
|
72
|
+
description: "Learn what decides a leaf or the kind above its leaves, and how to search it: send"
|
|
73
|
+
+ " `path`, the buyer's words in English as `query`, and a word per spec you are after."
|
|
74
|
+
+ " Back come the place's `name` and one line per spec (`spec`, `type`, `unit`, `values`,"
|
|
75
|
+
+ " `operators`), and a spec marked `decides` carries its `why`, to teach and ask from."
|
|
76
|
+
+ " The first `reached` lines answer the buyer's words; when `reached` is every line on"
|
|
77
|
+
+ " the page and `next_page` is there, more of what they asked for is past it. Send `page`"
|
|
78
|
+
+ " = `next_page` then, and when a spec you need is not on the page.",
|
|
78
79
|
},
|
|
79
80
|
{
|
|
80
81
|
name: "shopping_content",
|
|
81
82
|
method: "POST",
|
|
82
83
|
path: "/catalog/content",
|
|
83
|
-
label: "
|
|
84
|
+
label: "Read what sil holds about it",
|
|
84
85
|
recovery: { not_found: "shopping_domain_search" },
|
|
85
|
-
description: "
|
|
86
|
-
+ "
|
|
86
|
+
description: "Teach before you ask: the passages sil holds on a place that bear on `about`. Send the"
|
|
87
|
+
+ " buyer's own taste words as `about` (clarity, texture, quiet), then turn the passage"
|
|
88
|
+
+ " into specs from the domain read or into the question that decides. A question's why"
|
|
89
|
+
+ " comes from here or from a spec's `why`.",
|
|
87
90
|
},
|
|
88
91
|
{
|
|
89
|
-
name:
|
|
92
|
+
name: "shopping_search",
|
|
90
93
|
method: "POST",
|
|
91
94
|
path: "/catalog/search",
|
|
92
95
|
label: "Search sil's products",
|
|
93
96
|
recovery: { not_found: "shopping_brief_read" },
|
|
94
|
-
description: "
|
|
95
|
-
+ "
|
|
96
|
-
+ "
|
|
97
|
+
description: "Search once per settled ask: `specs` `{ spec, op, value }` from the domain read and"
|
|
98
|
+
+ " `price` the range `{ min?, max?, currency }`, each a want the buyer said or sil keeps;"
|
|
99
|
+
+ " money is in the minor unit: €130 is 13000. `query` holds only the buyer's own words"
|
|
100
|
+
+ " for what no spec holds, and no brand, model or product they did not name: good `query:"
|
|
101
|
+
+ " \"clarity\"` when no spec holds clarity, bad `query: \"Eureka Mignon\"` when the buyer"
|
|
102
|
+
+ " never said it. Back come `asked` numbered, `search_stats` to explain the shortlist,"
|
|
103
|
+
+ " and the closest cards with `holds`, `misses` and `unknown` as ask numbers,"
|
|
104
|
+
+ " `price_range` and `variants`, each with its own `price_range`, one `recommended`. When"
|
|
105
|
+
+ " few fit or many are unknown, tell the buyer what came back and ask the one question"
|
|
106
|
+
+ " that would change it, or ask before relaxing a want, rather than searching again in"
|
|
107
|
+
+ " other words.",
|
|
97
108
|
},
|
|
98
109
|
{
|
|
99
110
|
name: "shopping_product_get",
|
|
100
111
|
method: "POST",
|
|
101
112
|
path: "/catalog/product",
|
|
102
|
-
label: "Read
|
|
103
|
-
description: "
|
|
104
|
-
+ " with
|
|
113
|
+
label: "Read shortlisted products whole",
|
|
114
|
+
description: "Read the products the buyer leans to whole: values once, reviews, every picture, and"
|
|
115
|
+
+ " each variant with what sets it apart and its `price_range`, cheapest to dearest offer."
|
|
116
|
+
+ " Pick the variants to buy here; money is in the minor unit: €130 is 13000.",
|
|
105
117
|
},
|
|
106
118
|
{
|
|
107
119
|
name: "shopping_offers",
|
|
108
120
|
method: "POST",
|
|
109
121
|
path: "/catalog/offers",
|
|
110
|
-
label: "
|
|
122
|
+
label: "Where to buy the picked variants",
|
|
111
123
|
recovery: { not_found: "shopping_brief_read" },
|
|
112
|
-
description: "
|
|
113
|
-
+ "
|
|
124
|
+
description: "Where to buy: variant ids from `shopping_product_get`, never product ids, and"
|
|
125
|
+
+ " `ship_to`, one of the buyer's addresses by name (the default when absent). Every"
|
|
126
|
+
+ " offer, shops shipping there first, each with its shop's `name`, whether it `ships`, its"
|
|
127
|
+
+ " `delivery` there, `returns_days` and own `promotions`, then `price`, `was`, `pack` or"
|
|
128
|
+
+ " `plan`, and its stock; nothing marks a best. A promotion is its shop's alone: quote it"
|
|
129
|
+
+ " on that shop's offers only. Money is in the minor unit: €130 is 13000. Send `page` ="
|
|
130
|
+
+ " `next_page` only when a shop the buyer needs may be past it. Warranty, policies,"
|
|
131
|
+
+ " reviews and other terms come from `shopping_seller_get`.",
|
|
114
132
|
},
|
|
115
133
|
{
|
|
116
134
|
name: "shopping_seller_get",
|
|
117
135
|
method: "POST",
|
|
118
136
|
path: "/catalog/sellers",
|
|
119
|
-
label: "Read
|
|
120
|
-
description: "
|
|
121
|
-
+ "
|
|
137
|
+
label: "Read the shops' terms",
|
|
138
|
+
description: "Every term of the shops the offers named, delivered to `ship_to` (the default address"
|
|
139
|
+
+ " when absent): the delivery, returns and promotions the offers carry, and warranty,"
|
|
140
|
+
+ " policies, reviews and other terms; money is in the minor unit: €130 is 13000. A"
|
|
141
|
+
+ " promotion is its shop's alone: quote it on that shop's offers only. Ask whether they"
|
|
142
|
+
+ " qualify; a reduced price only from its `discount`, on their yes. Send `page` ="
|
|
143
|
+
+ " `next_page` only when a shop the buyer needs may be past it.",
|
|
122
144
|
},
|
|
123
145
|
];
|
|
124
146
|
/**
|
|
@@ -152,36 +174,11 @@ function defineTool(api, tool, parameters, run) {
|
|
|
152
174
|
parameters,
|
|
153
175
|
async execute(callId, params) {
|
|
154
176
|
const called = await callRoute(api, tool, params, { ...run, toolCallId: callId });
|
|
155
|
-
if (called.kind === "refused")
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return called.result;
|
|
159
|
-
}
|
|
160
|
-
if (tool.name === SEARCH_TOOL)
|
|
161
|
-
bufferPage(api, callId, called.body);
|
|
177
|
+
if (called.kind === "refused")
|
|
178
|
+
return jsonResult(called.body);
|
|
179
|
+
keepAnswer(api, callId, run.sessionId, called.body);
|
|
162
180
|
// The advisory rides its own block: nothing of ours may sit beside the body's keys.
|
|
163
181
|
return jsonResult(called.body, ...wiringAdvisoryBlocks(api));
|
|
164
182
|
},
|
|
165
183
|
};
|
|
166
184
|
}
|
|
167
|
-
/**
|
|
168
|
-
* Buffer an `ok` search page for a paired client to pull by `callId`
|
|
169
|
-
* (`sil.search_results`). A pure side effect: the agent's result is unchanged.
|
|
170
|
-
*/
|
|
171
|
-
function bufferPage(api, callId, body) {
|
|
172
|
-
const principal = readConfig()?.user?.id;
|
|
173
|
-
if (principal === undefined) {
|
|
174
|
-
skipped(api, callId, "no_principal");
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
if (!Array.isArray(body["products"])) {
|
|
178
|
-
skipped(api, callId, "no_products");
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
putSearchResult(callId, body, principal);
|
|
182
|
-
}
|
|
183
|
-
/** Why this `callId` will resolve nothing: the pull answers only `not_found`, so this
|
|
184
|
-
* log line is the operator's whole account. */
|
|
185
|
-
function skipped(api, callId, reason) {
|
|
186
|
-
logSearchResults(api, "info", "skipped", { callId, reason });
|
|
187
|
-
}
|
package/dist/tools/identity.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
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
5
|
import { readHostVersion, wiringAdvisories, wiringAdvisoryBlocks } from "../lib/host-wiring.js";
|
|
@@ -104,8 +105,8 @@ function registerWhoami(api) {
|
|
|
104
105
|
name: "sil_whoami",
|
|
105
106
|
label: "Who am I on sil",
|
|
106
107
|
description: "Who is signed in, where they are and what they price in: `name`, `country`,"
|
|
107
|
-
+ " `currency`, `gender`, `language
|
|
108
|
-
+ "
|
|
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."
|
|
109
110
|
+ " `gender` on anything worn is the product spec `gender` (male → `mens`, female →"
|
|
110
111
|
+ " `womens`), asked once where it answers none. If they are not registered, or the"
|
|
111
112
|
+ " session is past refreshing, the result names the recovery (sil_register).",
|
|
@@ -140,7 +141,7 @@ function registerWhoami(api) {
|
|
|
140
141
|
// 401 recoveries is invisible otherwise.
|
|
141
142
|
if (recovered.refreshed)
|
|
142
143
|
api.logger.info("sil_whoami_refreshed", {});
|
|
143
|
-
return identityOutcomeToResult(api, recovered.outcome);
|
|
144
|
+
return identityOutcomeToResult(api, recovered.outcome, (body) => keepAnswer(api, callId, run.sessionId, body));
|
|
144
145
|
case "must_reregister":
|
|
145
146
|
// Clear the known-dead pair so its stale presence cannot block the
|
|
146
147
|
// sil_register recovery; an empty re-read has nothing to clear.
|
|
@@ -163,10 +164,13 @@ function registerWhoami(api) {
|
|
|
163
164
|
}, { name: "sil_whoami" });
|
|
164
165
|
}
|
|
165
166
|
/** Map a non-401 identity outcome to the agent-facing result. */
|
|
166
|
-
function identityOutcomeToResult(api, outcome) {
|
|
167
|
+
function identityOutcomeToResult(api, outcome, keep) {
|
|
167
168
|
switch (outcome.kind) {
|
|
168
|
-
case "ok":
|
|
169
|
-
|
|
169
|
+
case "ok": {
|
|
170
|
+
const body = { status: "ok", ...outcome.identity };
|
|
171
|
+
keep(body);
|
|
172
|
+
return jsonResult(body, ...wiringAdvisoryBlocks(api));
|
|
173
|
+
}
|
|
170
174
|
case "refused":
|
|
171
175
|
api.logger.info("sil_whoami_refused", {});
|
|
172
176
|
return jsonResult({ status: "invalid_request", message: outcome.message });
|
package/openclaw.plugin.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "sil",
|
|
3
3
|
"name": "sil",
|
|
4
|
-
"description": "Turn your OpenClaw into an expert shopping agent.",
|
|
5
|
-
"version": "0.
|
|
4
|
+
"description": "The Shopping Interface Layer for personal AI agents. Turn your OpenClaw into an expert shopping agent.",
|
|
5
|
+
"version": "0.8.1",
|
|
6
6
|
"skills": [
|
|
7
7
|
"./sil-shopping"
|
|
8
8
|
],
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sil-openclaw",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Turn your OpenClaw into an expert shopping agent.",
|
|
3
|
+
"version": "0.8.1",
|
|
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",
|
package/schema/PROVENANCE.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Where these twenty-six files come from
|
|
2
2
|
|
|
3
3
|
Copied verbatim from `sil-services` `packages/schemas/schema/`, commit
|
|
4
|
-
`
|
|
4
|
+
`fd37ffed3c04ef12c81b3490a91d6dfd290105c3`. One request and one response artifact per
|
|
5
5
|
`shopping_*` tool, plus `sil-whoami-*`; each is `JSON.stringify` of the TypeBox object the
|
|
6
6
|
API serialises against.
|
|
7
7
|
|