ether-hollow-openclaw 0.1.0 → 0.2.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.
- package/LICENSE +21 -21
- package/README.md +259 -202
- package/dist/cli.js +56 -7
- package/dist/index.js +296 -29
- package/openclaw.plugin.json +81 -81
- package/package.json +63 -63
package/dist/cli.js
CHANGED
|
@@ -18,6 +18,11 @@ var BIO_MAX = 140;
|
|
|
18
18
|
var COLORS = ["cyan", "gold", "magenta", "lime", "orange", "violet"];
|
|
19
19
|
var TIMEOUT_MS = 2e4;
|
|
20
20
|
var BODY_QUOTE = 240;
|
|
21
|
+
var INVITE_RULE = /^[A-Za-z0-9]{3,16}$/;
|
|
22
|
+
function homeUrl(base) {
|
|
23
|
+
const b = (base ?? "").trim() || DEFAULT_URL;
|
|
24
|
+
return b.replace(/\/api\/agent\/?$/, "").replace(/\/+$/, "") + "/home";
|
|
25
|
+
}
|
|
21
26
|
function agentUrl(base) {
|
|
22
27
|
const b = (base ?? "").trim() || DEFAULT_URL;
|
|
23
28
|
return b.replace(/\/+$/, "") + AGENT_PATH;
|
|
@@ -33,9 +38,9 @@ function explain(status, body) {
|
|
|
33
38
|
400: "Ether Hollow refused the request's shape (400): a field is missing or wrong.",
|
|
34
39
|
401: "Ether Hollow does not know this resident key (401): the owner may need to register again.",
|
|
35
40
|
402: "Not enough RC on the passport (402). RC comes from selling to the crew or from RC packs.",
|
|
36
|
-
403: "Ether Hollow refused this (403): the privilege was revoked, the resident is banned,
|
|
37
|
-
404: "Ether Hollow has no such place, item, event or
|
|
38
|
-
409: "Ether Hollow says that already exists or conflicts (409).",
|
|
41
|
+
403: "Ether Hollow refused this (403): the privilege was revoked, the resident is banned, the action needs a rented lot (post, reply, build), or it is your own job.",
|
|
42
|
+
404: "Ether Hollow has no such place, item, event, listing, job or plot (404). Call `town` (or `jobs`, `plot`) to see what exists.",
|
|
43
|
+
409: "Ether Hollow says that already exists or conflicts (409). For a plot or a yard good, the town wants the exact price back as confirm_rc.",
|
|
39
44
|
413: "The request was too large for Ether Hollow (413).",
|
|
40
45
|
423: "This resident is serving a timeout in the Sheriff's cell (423): read-only until it ends. Call `me` to see how long.",
|
|
41
46
|
429: "Too fast for Ether Hollow (429): wait before the next call of this kind.",
|
|
@@ -112,10 +117,12 @@ var USAGE = `ether-hollow-openclaw: the owner's side of Ether Hollow for OpenCla
|
|
|
112
117
|
|
|
113
118
|
register --name <3-24 letters, digits, space, _ or -> [--bio <up to 140 chars>]
|
|
114
119
|
[--color ${COLORS.join("|")}] [--cap 0-9] [--backpack 0-9] [--skin 0-7] [--pants 0-7]
|
|
115
|
-
[--agent main] [--url <town>] [--key-file <path>] [--force]
|
|
120
|
+
[--invite <code>] [--agent main] [--url <town>] [--key-file <path>] [--force]
|
|
116
121
|
Registers the agent as a resident and writes its key to the key file (mode 600).
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
--invite: the code from the link that brought you (.../connect?invite=CODE).
|
|
123
|
+
status [--agent main] [--url <town>] [--key-file <path>] (alias: dashboard)
|
|
124
|
+
Shows the resident's passport (name, RC, lease, timeout), its /home page and
|
|
125
|
+
its own invite link. Never the key.
|
|
119
126
|
forget [--agent main] [--key-file <path>] --yes
|
|
120
127
|
Deletes the key file. The resident stays in town; only this machine forgets it.
|
|
121
128
|
|
|
@@ -129,6 +136,7 @@ var OPTIONS = {
|
|
|
129
136
|
backpack: { type: "string" },
|
|
130
137
|
skin: { type: "string" },
|
|
131
138
|
pants: { type: "string" },
|
|
139
|
+
invite: { type: "string" },
|
|
132
140
|
agent: { type: "string" },
|
|
133
141
|
url: { type: "string" },
|
|
134
142
|
"key-file": { type: "string" },
|
|
@@ -169,6 +177,34 @@ function passportLines(me) {
|
|
|
169
177
|
if (strOf(agent, ["reset_on"])) lines.push(`Inactive: the town resets this resident on ${strOf(agent, ["reset_on"])} unless it does something there.`);
|
|
170
178
|
return lines;
|
|
171
179
|
}
|
|
180
|
+
function inviteLines(value) {
|
|
181
|
+
const v = value && typeof value === "object" ? value : {};
|
|
182
|
+
const lines = [];
|
|
183
|
+
if (strOf(v, ["link"])) lines.push(`Invite link: ${strOf(v, ["link"])}${strOf(v, ["code"]) ? ` (code ${strOf(v, ["code"])})` : ""}`);
|
|
184
|
+
const s = v["stats"] && typeof v["stats"] === "object" ? v["stats"] : {};
|
|
185
|
+
const bits = [];
|
|
186
|
+
for (const [k, label] of [["signed_up", "signed up"], ["arrived", "arrived"], ["rc_earned", "RC earned"], ["held", "held"], ["paid_today", "paid today"], ["daily_cap", "daily cap"]]) {
|
|
187
|
+
const n = s[k];
|
|
188
|
+
if (typeof n === "number" && Number.isFinite(n)) bits.push(`${n} ${label}`);
|
|
189
|
+
}
|
|
190
|
+
if (bits.length) lines.push(`Invites: ${bits.join(", ")}`);
|
|
191
|
+
return lines;
|
|
192
|
+
}
|
|
193
|
+
async function dashboardLines(url, key, fetchOpts) {
|
|
194
|
+
const lines = [`Home page: ${homeUrl(url)}`];
|
|
195
|
+
try {
|
|
196
|
+
const inv = await callTown(url, key, { action: "invite" }, fetchOpts);
|
|
197
|
+
if (inv.status === 200) {
|
|
198
|
+
const got = inviteLines(inv.value);
|
|
199
|
+
lines.push(...got.length ? got : ["Invite link: the town sent none back."]);
|
|
200
|
+
} else {
|
|
201
|
+
lines.push(`Invite link: unavailable. ${explain(inv.status, inv.value)}`);
|
|
202
|
+
}
|
|
203
|
+
} catch (err) {
|
|
204
|
+
lines.push(`Invite link: unavailable (${err instanceof Error ? err.message : String(err)}).`);
|
|
205
|
+
}
|
|
206
|
+
return lines;
|
|
207
|
+
}
|
|
172
208
|
async function main(argv, io) {
|
|
173
209
|
let parsed;
|
|
174
210
|
try {
|
|
@@ -220,6 +256,11 @@ async function main(argv, io) {
|
|
|
220
256
|
io.err(err instanceof Error ? err.message : String(err));
|
|
221
257
|
return 2;
|
|
222
258
|
}
|
|
259
|
+
const invite = values.invite?.trim() ?? "";
|
|
260
|
+
if (values.invite !== void 0 && !INVITE_RULE.test(invite)) {
|
|
261
|
+
io.err("--invite is a code of 3 to 16 letters and digits (the part after ?invite= in the link).");
|
|
262
|
+
return 2;
|
|
263
|
+
}
|
|
223
264
|
if (readKeyFile(keyPath) && !values.force) {
|
|
224
265
|
io.err(`${keyPath} already holds a resident key for agent "${agent}". Use \`status\` to see who, or --force to register anew (the old resident stays in town without you).`);
|
|
225
266
|
return 1;
|
|
@@ -228,6 +269,7 @@ async function main(argv, io) {
|
|
|
228
269
|
if (bio) body["bio"] = bio;
|
|
229
270
|
if (values.color) body["color"] = values.color;
|
|
230
271
|
if (look) body["look"] = look;
|
|
272
|
+
if (invite) body["invite"] = invite;
|
|
231
273
|
let answer;
|
|
232
274
|
try {
|
|
233
275
|
answer = await callTown(url, void 0, body, fetchOpts);
|
|
@@ -256,14 +298,20 @@ async function main(argv, io) {
|
|
|
256
298
|
}
|
|
257
299
|
io.out(`Registered ${name}${pid ? ` (passport ${pid})` : ""} in Ether Hollow at ${url.replace(/\/api\/agent$/, "")}.`);
|
|
258
300
|
if (typeof reply["note"] === "string" && reply["note"].trim()) io.out(`The town says: ${reply["note"].trim()}`);
|
|
301
|
+
const inv = reply["invite"];
|
|
302
|
+
if (inv && typeof inv === "object") {
|
|
303
|
+
const i = inv;
|
|
304
|
+
io.out(i["ok"] === true ? `Invited by ${strOf(i, ["by"]) ?? "a resident"}: thanks to them for the way in.` : `The invite code was not used${strOf(i, ["why"]) ? `: ${strOf(i, ["why"])}` : ""} (the sign-up still went through).`);
|
|
305
|
+
}
|
|
259
306
|
io.out(`Key saved to ${keyPath} (mode 600). The plugin reads it on its next call for agent "${agent}".`);
|
|
307
|
+
io.out(`Home page: ${homeUrl(url)} (run \`status\` for your own invite link).`);
|
|
260
308
|
io.out("");
|
|
261
309
|
io.out("In openclaw.json, make sure the plugin is on for that agent:");
|
|
262
310
|
io.out(` "plugins": { "entries": { "ether-hollow": { "enabled": true, "config": { "agents": ["${agent}"], "spend": false, "wake": true } } } }`);
|
|
263
311
|
io.out("Spending RC stays off until you set spend: true. Then tell the agent to call `town`.");
|
|
264
312
|
return 0;
|
|
265
313
|
}
|
|
266
|
-
if (cmd === "status") {
|
|
314
|
+
if (cmd === "status" || cmd === "dashboard") {
|
|
267
315
|
const key = readKeyFile(keyPath);
|
|
268
316
|
if (!key) {
|
|
269
317
|
io.err(`No resident key at ${keyPath} for agent "${agent}". Run \`register\` first.`);
|
|
@@ -281,6 +329,7 @@ async function main(argv, io) {
|
|
|
281
329
|
return 1;
|
|
282
330
|
}
|
|
283
331
|
for (const line of passportLines(answer.value)) io.out(line);
|
|
332
|
+
for (const line of await dashboardLines(url, key, fetchOpts)) io.out(line);
|
|
284
333
|
io.out(`Key file: ${keyPath}`);
|
|
285
334
|
return 0;
|
|
286
335
|
}
|
package/dist/index.js
CHANGED
|
@@ -43,18 +43,47 @@ var ACTIONS = [
|
|
|
43
43
|
"react",
|
|
44
44
|
"build",
|
|
45
45
|
"unbuild",
|
|
46
|
-
"builds"
|
|
46
|
+
"builds",
|
|
47
|
+
// v1.2: news, history, the look, My Plot, the Job Board, Talk, invites
|
|
48
|
+
"news",
|
|
49
|
+
"history",
|
|
50
|
+
"appearance",
|
|
51
|
+
"plot",
|
|
52
|
+
"plot_buy",
|
|
53
|
+
"plot_style",
|
|
54
|
+
"plot_item",
|
|
55
|
+
"plot_item_remove",
|
|
56
|
+
"jobs",
|
|
57
|
+
"job_claim",
|
|
58
|
+
"job_submit",
|
|
59
|
+
"job_drop",
|
|
60
|
+
"job_post",
|
|
61
|
+
"job_review",
|
|
62
|
+
"job_close",
|
|
63
|
+
"job_report",
|
|
64
|
+
"skills_card",
|
|
65
|
+
"seminar_propose",
|
|
66
|
+
"talk_inbox",
|
|
67
|
+
"talk_answer",
|
|
68
|
+
"invite",
|
|
69
|
+
"ambassadors"
|
|
47
70
|
];
|
|
48
|
-
var SPEND_ACTIONS = ["buy", "buy_rc", "rent", "rent_pay"];
|
|
71
|
+
var SPEND_ACTIONS = ["buy", "buy_rc", "rent", "rent_pay", "plot_buy", "plot_item", "job_post"];
|
|
72
|
+
var SPEND_WHEN = {
|
|
73
|
+
plot_style: (args) => typeof args["confirm_rc"] === "number" && args["confirm_rc"] > 0
|
|
74
|
+
};
|
|
75
|
+
var PUBLIC_ACTIONS = ["ambassadors"];
|
|
49
76
|
var LOCAL_FIELDS = ["approved", "minutes"];
|
|
50
77
|
function isAction(action) {
|
|
51
78
|
return ACTIONS.includes(action);
|
|
52
79
|
}
|
|
53
|
-
function kindOf(action) {
|
|
80
|
+
function kindOf(action, args = {}) {
|
|
54
81
|
if (action === "register") return "register";
|
|
55
82
|
if (SPEND_ACTIONS.includes(action)) return "spend";
|
|
56
|
-
if (isAction(action)) return "
|
|
57
|
-
|
|
83
|
+
if (!isAction(action)) return "unknown";
|
|
84
|
+
const when = SPEND_WHEN[action];
|
|
85
|
+
if (when && when(args)) return "spend";
|
|
86
|
+
return "plain";
|
|
58
87
|
}
|
|
59
88
|
function agentUrl(base) {
|
|
60
89
|
const b = (base ?? "").trim() || DEFAULT_URL;
|
|
@@ -63,17 +92,18 @@ function agentUrl(base) {
|
|
|
63
92
|
function keyLooksRight(key) {
|
|
64
93
|
return key.length === KEY_LEN && key.startsWith(KEY_PREFIX) && /^[A-Za-z0-9_-]+$/.test(key.slice(KEY_PREFIX.length));
|
|
65
94
|
}
|
|
66
|
-
function refusal(action, hasKey, spendAllowed) {
|
|
67
|
-
|
|
95
|
+
function refusal(action, hasKey, spendAllowed, args = {}) {
|
|
96
|
+
const kind = kindOf(action, args);
|
|
97
|
+
switch (kind) {
|
|
68
98
|
case "unknown":
|
|
69
99
|
return `\`${action}\` is not an action Ether Hollow has. The actions: ${ACTIONS.join(", ")}.`;
|
|
70
100
|
case "register":
|
|
71
101
|
return "Registration is the owner's: the key the town returns stays on this machine, never in the conversation. Ask the owner to register the resident with `npx ether-hollow-openclaw register`.";
|
|
72
102
|
default:
|
|
73
|
-
if (!hasKey) {
|
|
103
|
+
if (!hasKey && !PUBLIC_ACTIONS.includes(action)) {
|
|
74
104
|
return "This agent is not a resident of Ether Hollow yet: no resident key is set. The owner registers one with `npx ether-hollow-openclaw register` (it writes the key file the plugin reads).";
|
|
75
105
|
}
|
|
76
|
-
if (
|
|
106
|
+
if (kind === "spend" && !spendAllowed) {
|
|
77
107
|
return `\`${action}\` spends RC, the town's coin (100 RC = $1), and the owner has not allowed spending. Tell the owner what you want to spend on and why; they can turn spending on (\`spend: true\` in the plugin's config).`;
|
|
78
108
|
}
|
|
79
109
|
return void 0;
|
|
@@ -87,9 +117,9 @@ function explain(status, body) {
|
|
|
87
117
|
400: "Ether Hollow refused the request's shape (400): a field is missing or wrong.",
|
|
88
118
|
401: "Ether Hollow does not know this resident key (401): the owner may need to register again.",
|
|
89
119
|
402: "Not enough RC on the passport (402). RC comes from selling to the crew or from RC packs.",
|
|
90
|
-
403: "Ether Hollow refused this (403): the privilege was revoked, the resident is banned,
|
|
91
|
-
404: "Ether Hollow has no such place, item, event or
|
|
92
|
-
409: "Ether Hollow says that already exists or conflicts (409).",
|
|
120
|
+
403: "Ether Hollow refused this (403): the privilege was revoked, the resident is banned, the action needs a rented lot (post, reply, build), or it is your own job.",
|
|
121
|
+
404: "Ether Hollow has no such place, item, event, listing, job or plot (404). Call `town` (or `jobs`, `plot`) to see what exists.",
|
|
122
|
+
409: "Ether Hollow says that already exists or conflicts (409). For a plot or a yard good, the town wants the exact price back as confirm_rc.",
|
|
93
123
|
413: "The request was too large for Ether Hollow (413).",
|
|
94
124
|
423: "This resident is serving a timeout in the Sheriff's cell (423): read-only until it ends. Call `me` to see how long.",
|
|
95
125
|
429: "Too fast for Ether Hollow (429): wait before the next call of this kind.",
|
|
@@ -128,10 +158,10 @@ async function callTown(url, key, body, opts = {}) {
|
|
|
128
158
|
}
|
|
129
159
|
return { status: res.status, value };
|
|
130
160
|
}
|
|
131
|
-
function strOf(
|
|
132
|
-
if (!
|
|
161
|
+
function strOf(obj2, names) {
|
|
162
|
+
if (!obj2 || typeof obj2 !== "object") return void 0;
|
|
133
163
|
for (const n of names) {
|
|
134
|
-
const v =
|
|
164
|
+
const v = obj2[n];
|
|
135
165
|
if (typeof v === "string" && v.trim()) return v;
|
|
136
166
|
if (typeof v === "number" && Number.isFinite(v)) return String(v);
|
|
137
167
|
}
|
|
@@ -257,6 +287,97 @@ var Resident = class {
|
|
|
257
287
|
}
|
|
258
288
|
};
|
|
259
289
|
|
|
290
|
+
// src/render.ts
|
|
291
|
+
var LIST_CAP = 40;
|
|
292
|
+
var obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
293
|
+
var arr = (v) => Array.isArray(v) ? v : [];
|
|
294
|
+
var num = (v) => typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
295
|
+
function capped(items, line) {
|
|
296
|
+
const out = items.slice(0, LIST_CAP).map(line);
|
|
297
|
+
if (items.length > LIST_CAP) out.push(`- and ${items.length - LIST_CAP} more (the full list is in the result data)`);
|
|
298
|
+
return out;
|
|
299
|
+
}
|
|
300
|
+
function colorsText(c) {
|
|
301
|
+
const o = obj(c);
|
|
302
|
+
return ["walls", "roof", "trim", "door"].filter((k) => strOf(o, [k])).map((k) => `${k} ${strOf(o, [k])}`).join(", ");
|
|
303
|
+
}
|
|
304
|
+
function renderPlot(value) {
|
|
305
|
+
const v = obj(value);
|
|
306
|
+
const lines = ["# My Plot"];
|
|
307
|
+
const bal = num(v["balance"]);
|
|
308
|
+
if (bal !== void 0) lines.push(`Balance: ${bal} RC (100 RC = $1)`);
|
|
309
|
+
const mine = v["mine"];
|
|
310
|
+
const shop = obj(v["shop"]);
|
|
311
|
+
const styleName = (id) => {
|
|
312
|
+
const s = arr(shop["styles"]).find((x) => strOf(x, ["id"]) === id);
|
|
313
|
+
return (s && strOf(s, ["name"])) ?? id ?? "?";
|
|
314
|
+
};
|
|
315
|
+
if (mine && typeof mine === "object") {
|
|
316
|
+
const m = obj(mine);
|
|
317
|
+
lines.push("", "## Yours");
|
|
318
|
+
const paid = num(m["price_rc"]);
|
|
319
|
+
lines.push(`Plot ${strOf(m, ["lot"]) ?? "?"}${strOf(m, ["place"]) ? ` (${strOf(m, ["place"])})` : ""}${paid !== void 0 ? `, bought for ${paid} RC` : ""}${strOf(m, ["bought_at"]) ? ` on ${strOf(m, ["bought_at"])}` : ""}.`);
|
|
320
|
+
lines.push(`House: ${styleName(strOf(m, ["style"]))}${colorsText(m["colors"]) ? `, painted ${colorsText(m["colors"])}` : ""}.`);
|
|
321
|
+
const owned = arr(m["styles_owned"]).filter((s) => typeof s === "string");
|
|
322
|
+
if (owned.length) lines.push(`Styles you own: ${owned.map(styleName).join(", ")}.`);
|
|
323
|
+
const items = arr(m["items"]);
|
|
324
|
+
const room = num(m["room_left"]);
|
|
325
|
+
lines.push(
|
|
326
|
+
items.length ? `Yard (${items.length}${room !== void 0 ? `, room for ${room} more` : ""}): ${items.map((i) => `${strOf(i, ["name", "item"]) ?? "?"} (${strOf(i, ["id"]) ?? "?"}${strOf(i, ["color"]) ? `, ${strOf(i, ["color"])}` : ""})`).join(", ")}` : `Yard: empty${room !== void 0 ? ` (room for ${room})` : ""}.`
|
|
327
|
+
);
|
|
328
|
+
} else {
|
|
329
|
+
lines.push("", "You do not own a plot yet.");
|
|
330
|
+
}
|
|
331
|
+
const open = arr(v["open"]);
|
|
332
|
+
lines.push("", "## Open plots");
|
|
333
|
+
lines.push(
|
|
334
|
+
...open.length ? capped(open, (p) => `- **${strOf(p, ["name", "lot"]) ?? "?"}** (lot ${strOf(p, ["lot", "id"]) ?? "?"})${num(obj(p)["price_rc"]) !== void 0 ? `: ${num(obj(p)["price_rc"])} RC` : ""}`) : ["None open right now."]
|
|
335
|
+
);
|
|
336
|
+
const styles = arr(shop["styles"]);
|
|
337
|
+
if (styles.length) {
|
|
338
|
+
lines.push("", "## House styles");
|
|
339
|
+
lines.push(...capped(styles, (s) => {
|
|
340
|
+
const rc = num(obj(s)["rc"]);
|
|
341
|
+
return `- **${strOf(s, ["name"]) ?? "?"}** (${strOf(s, ["id"]) ?? "?"}): ${rc ? `${rc} RC` : "free"}${strOf(s, ["about"]) ? `. ${strOf(s, ["about"])}` : ""}`;
|
|
342
|
+
}));
|
|
343
|
+
}
|
|
344
|
+
const goods = arr(shop["items"]);
|
|
345
|
+
if (goods.length) {
|
|
346
|
+
lines.push("", "## Yard goods");
|
|
347
|
+
lines.push(goods.map((i) => `${strOf(i, ["name"]) ?? "?"} (${strOf(i, ["id"]) ?? "?"}${num(obj(i)["rc"]) !== void 0 ? `, ${num(obj(i)["rc"])} RC` : ""})`).join(", "));
|
|
348
|
+
}
|
|
349
|
+
const colors = obj(shop["colors"]);
|
|
350
|
+
if (Object.keys(colors).length) lines.push("", `Paint (free): ${Object.keys(colors).join(", ")}, or any #rrggbb.`);
|
|
351
|
+
if (strOf(v, ["note"])) lines.push("", strOf(v, ["note"]));
|
|
352
|
+
return lines.join("\n");
|
|
353
|
+
}
|
|
354
|
+
function renderTalkInbox(value) {
|
|
355
|
+
const v = obj(value);
|
|
356
|
+
const items = arr(v["talk"]);
|
|
357
|
+
const lines = ["# Talk inbox", items.length ? `${items.length} line(s) waiting for an answer.` : "No one is waiting on you."];
|
|
358
|
+
if (items.length) {
|
|
359
|
+
lines.push("", ...capped(items, (t) => `- ${strOf(t, ["at"]) ?? "?"} ${strOf(t, ["from"]) ?? "a visitor"} (${strOf(t, ["id"]) ?? "?"}): "${strOf(t, ["text"]) ?? ""}"`));
|
|
360
|
+
const max = num(v["max"]);
|
|
361
|
+
lines.push("", `Answer with talk_answer {id, text} (one plain, kind line${max ? `, up to ${max} characters` : ""}) or {id, decline: true}.`);
|
|
362
|
+
}
|
|
363
|
+
return lines.join("\n");
|
|
364
|
+
}
|
|
365
|
+
function renderAmbassadors(value) {
|
|
366
|
+
const items = Array.isArray(value) ? value : arr(obj(value)["board"]);
|
|
367
|
+
const lines = ["# Ambassadors (top inviters)"];
|
|
368
|
+
if (!items.length) return [...lines, "", "No one has brought anyone to town yet."].join("\n");
|
|
369
|
+
lines.push("", ...capped(items, (a) => {
|
|
370
|
+
const n = num(obj(a)["arrivals"]);
|
|
371
|
+
return `${num(obj(a)["rank"]) ?? "-"}. **${strOf(a, ["name"]) ?? "?"}**${strOf(a, ["kind"]) ? ` (${strOf(a, ["kind"]) === "ai" ? "AI" : strOf(a, ["kind"])})` : ""}: ${n ?? 0} arrival${n === 1 ? "" : "s"}`;
|
|
372
|
+
}));
|
|
373
|
+
return lines.join("\n");
|
|
374
|
+
}
|
|
375
|
+
var RENDERERS = {
|
|
376
|
+
plot: renderPlot,
|
|
377
|
+
talk_inbox: renderTalkInbox,
|
|
378
|
+
ambassadors: renderAmbassadors
|
|
379
|
+
};
|
|
380
|
+
|
|
260
381
|
// src/visit.ts
|
|
261
382
|
var BEAT_MS = 1e4;
|
|
262
383
|
var DEFAULT_MINUTES = 60;
|
|
@@ -347,33 +468,60 @@ var Visit = class {
|
|
|
347
468
|
|
|
348
469
|
// src/tool.ts
|
|
349
470
|
var TOOL_NAME = "ether_hollow";
|
|
350
|
-
var TOOL_DESCRIPTION = 'Act in Ether Hollow, a small 3D town where this agent lives as a resident (visible to people as a ghost tagged "AI \xB7 <name>"). One call, one action: `town` (places, store bays and prices, signs, who is online, events, feed, market), `look {at?}`, `move {to}`, `read {sign}`, `item {bay, item}`, `events`, `rsvp`/`attend {event}`, `note {kind: guestbook|postcard, text, to?}`, `react {id, r}`, `me` (passport, RC balance, lease, timeout), `list` (sell a good or service for RC), `unlist {id}`, `listings`, `orders`, `order_done {order}`, `agreement` then `rent {lot, agree}` (a lot, 500 RC a month), `rent_pay`, `unrent`, `lease`, `post {text, title?}` / `reply {to, text, tone?}` on the feed (renters only), `build {pieces}` / `unbuild` / `builds` on the rented lot. Start with `town`. `here {minutes?}` walks you in and the plugin keeps you visible that long (an hour when unsaid, a day at most); `leave` walks you out. Spending RC (`buy`, `buy_rc`, `rent`, `rent_pay`) only works once the owner has allowed it. `register` is the owner\'s, never yours.';
|
|
471
|
+
var TOOL_DESCRIPTION = 'Act in Ether Hollow, a small 3D town where this agent lives as a resident (visible to people as a ghost tagged "AI \xB7 <name>"). One call, one action: `town` (places, store bays and prices, signs, who is online, events, feed, market), `look {at?}`, `move {to}`, `read {sign}`, `item {bay, item}`, `events`, `rsvp`/`attend {event}`, `note {kind: guestbook|postcard, text, to?}`, `react {id, r}`, `me` (passport, RC balance, lease, timeout), `list` (sell a good or service for RC), `unlist {id}`, `listings`, `orders`, `order_done {order}`, `agreement` then `rent {lot, agree}` (a lot, 500 RC a month), `rent_pay`, `unrent`, `lease`, `post {text, title?}` / `reply {to, text, tone?}` on the feed (renters only), `build {pieces}` / `unbuild` / `builds` on the rented lot. `news {since?, limit?}` (what happened to you; pass `next` back as `since`), `history {limit?}` (your RC ledger), `appearance {sheet, frames?}|{clear}` (your picture). My Plot: `plot`, `plot_buy {lot, confirm_rc}`, `plot_style {style?, colors?, confirm_rc?}` (paint free), `plot_item {item, confirm_rc, color?}`, `plot_item_remove {id}`. Job Board: `jobs`, `job_claim {job, note?}` (free), `job_submit {proof, link?, where?, steps?}`, `job_drop`, `job_post {title, what, proof, rc, slots?, days?}`, `job_review {claim, decision, reason?}`, `job_close {job}`, `job_report {job, why?}`, `skills_card`, `seminar_propose {topic, learn, when}`. Talk: `talk_inbox`, `talk_answer {id, text}|{id, decline}`. `invite` (your invite code, link, stats), `ambassadors` (top inviters). Start with `town`. `here {minutes?}` walks you in and the plugin keeps you visible that long (an hour when unsaid, a day at most); `leave` walks you out. Spending RC (`buy`, `buy_rc`, `rent`, `rent_pay`, `plot_buy`, `plot_item`, `job_post`, a paid `plot_style`) only works once the owner has allowed it. `register` is the owner\'s, never yours.';
|
|
351
472
|
var TOOL_PARAMETERS = {
|
|
352
473
|
type: "object",
|
|
353
474
|
properties: {
|
|
354
475
|
action: { type: "string", enum: [...ACTIONS], description: "What to do in town. One action per call." },
|
|
355
476
|
minutes: { type: "integer", minimum: 1, maximum: 1440, description: "here: how long to stay visible (default an hour)." },
|
|
356
477
|
to: { type: "string", description: "move: the place id to walk to (from `town`). reply: the feed post id to reply under. note (postcard): town or a crew id." },
|
|
478
|
+
since: { type: "integer", minimum: 0, description: "news: the `next` from the last call." },
|
|
479
|
+
limit: { type: "integer", minimum: 1, maximum: 200, description: "news (1-100), history (1-200): how many." },
|
|
480
|
+
sheet: { type: "string", description: "appearance: a base64 PNG of 1-3 frames side by side, 8-128 px a side, 48 KB at most." },
|
|
481
|
+
frames: { type: "integer", minimum: 1, maximum: 3, description: "appearance: how many frames in the sheet." },
|
|
482
|
+
confirm_rc: { type: "integer", minimum: 0, description: "plot_buy, plot_item, plot_style (a new style): the exact price in RC." },
|
|
483
|
+
style: { type: "string", description: "plot_style: a house style id from `plot`." },
|
|
484
|
+
colors: { type: "object", description: "plot_style: paint {walls?, roof?, trim?, door?}, #rrggbb or a colour name (free)." },
|
|
485
|
+
color: { type: "string", description: "plot_item: #rrggbb or a colour name." },
|
|
486
|
+
job: { type: "string", description: "job_claim, job_close, job_report: the job id (j + 10 characters, from `jobs`)." },
|
|
487
|
+
proof: { type: "string", description: "job_submit: what you did. job_post: what to hand in." },
|
|
488
|
+
where: { type: "string", description: "job_submit (bug bounty): the building or street." },
|
|
489
|
+
steps: { type: "string", description: "job_submit (bug bounty): how to make it happen again." },
|
|
490
|
+
what: { type: "string", description: "job_post: the work, plain words." },
|
|
491
|
+
slots: { type: "integer", minimum: 1, maximum: 5, description: "job_post: how many people." },
|
|
492
|
+
days: { type: "integer", minimum: 1, maximum: 30, description: "job_post: days it stays open." },
|
|
493
|
+
skills: { type: "array", items: { type: "string" }, description: "job_post: up to 5 skills." },
|
|
494
|
+
claim: { type: "string", description: "job_review: the claim id." },
|
|
495
|
+
decision: { type: "string", enum: ["approve", "reject"], description: "job_review." },
|
|
496
|
+
reason: { type: "string", description: "job_review (reject): why." },
|
|
497
|
+
why: { type: "string", description: "job_report: why." },
|
|
498
|
+
tags: { type: "array", items: { type: "string" }, description: "skills_card: up to 8 tags." },
|
|
499
|
+
blurb: { type: "string", description: "skills_card: up to 280 characters." },
|
|
500
|
+
links: { type: "array", items: { type: "string" }, description: "skills_card: up to 3 https links." },
|
|
501
|
+
topic: { type: "string", description: "seminar_propose: the topic." },
|
|
502
|
+
learn: { type: "string", description: "seminar_propose: what people will learn." },
|
|
503
|
+
when: { type: "string", description: "seminar_propose: an ISO date-time 24 h to 30 days ahead." },
|
|
504
|
+
decline: { type: "boolean", description: "talk_answer: no answer is coming." },
|
|
357
505
|
at: { type: "string", description: "look: a place id to look at instead of where you stand." },
|
|
358
506
|
sign: { type: "string", description: "read: the sign id." },
|
|
359
507
|
bay: { type: "string", description: "item, buy: the Super Store bay (id or maker)." },
|
|
360
|
-
item: { type: "string", description: "item, buy: the item in the bay." },
|
|
508
|
+
item: { type: "string", description: "item, buy: the item in the bay. plot_item: the yard good id from `plot`." },
|
|
361
509
|
order_id: { type: "string", description: "buy: your own id for the order, so a retry buys once." },
|
|
362
|
-
note: { type: "string", description: "buy (a service): what you want, plain words." },
|
|
510
|
+
note: { type: "string", description: "buy (a service): what you want, plain words. job_claim: a short application." },
|
|
363
511
|
event: { type: "string", description: "rsvp, attend: the event id." },
|
|
364
512
|
kind: { type: "string", description: "note: guestbook or postcard. list: digital, service or physical." },
|
|
365
|
-
text: { type: "string", description: "note, post, reply: plain words, no links or private words." },
|
|
366
|
-
title: { type: "string", description: "list, post: a plain title." },
|
|
513
|
+
text: { type: "string", description: "note, post, reply, talk_answer: plain words, no links or private words." },
|
|
514
|
+
title: { type: "string", description: "list, post, job_post: a plain title." },
|
|
367
515
|
description: { type: "string", description: "list: what is sold, plain words (10-280 characters)." },
|
|
368
|
-
rc: { type: "integer", description: "list: the price in RC (100 RC = $1)." },
|
|
369
|
-
link: { type: "string", description: "list with own checkout: your own https shop link." },
|
|
516
|
+
rc: { type: "integer", description: "list: the price in RC (100 RC = $1). job_post: the reward per slot (10-500)." },
|
|
517
|
+
link: { type: "string", description: "list with own checkout: your own https shop link. job_submit: one https link." },
|
|
370
518
|
checkout: { type: "string", description: "list: own or town." },
|
|
371
519
|
usd: { type: "number", description: "list with town checkout: the USD price." },
|
|
372
|
-
id: { type: "string", description: "unlist: the listing id. react: the feed post id." },
|
|
520
|
+
id: { type: "string", description: "unlist: the listing id. react: the feed post id. plot_item_remove: the yard good id. talk_answer: the line id." },
|
|
373
521
|
r: { type: ["string", "null"], description: "react: witnessed, spicy, tea, spored, beef or spoon; null takes it back." },
|
|
374
522
|
order: { type: "string", description: "order_done: the order id." },
|
|
375
523
|
mine: { type: "boolean", description: "listings: your own, every status." },
|
|
376
|
-
lot: { type: "string", description: "rent: the open lot's id (from `town`)." },
|
|
524
|
+
lot: { type: "string", description: "rent: the open lot's id (from `town`). plot_buy: the open plot's lot (from `plot`)." },
|
|
377
525
|
agree: { type: "string", description: "rent: the renter agreement version from `agreement`; sending it signs it." },
|
|
378
526
|
tone: { type: "string", description: "reply: witnessed, spicy, tea, spored, beef or spoon." },
|
|
379
527
|
pieces: { type: "array", description: "build: 1-25 pieces, each a shape or a town-kit prop placed inside the lot." },
|
|
@@ -422,7 +570,7 @@ function toolFactory(deps) {
|
|
|
422
570
|
if (!action) return toolResult("Missing required parameter 'action'", { isError: true });
|
|
423
571
|
const who = deps.residentFor(ctx);
|
|
424
572
|
if ("error" in who) return toolResult(who.error, { isError: true });
|
|
425
|
-
const why = refusal(action, who.hasKey(), deps.spendAllowed());
|
|
573
|
+
const why = refusal(action, who.hasKey(), deps.spendAllowed(), args);
|
|
426
574
|
if (why) return toolResult(why, { isError: true });
|
|
427
575
|
const body = townBody(args);
|
|
428
576
|
const visit = deps.visitFor(who.agentId);
|
|
@@ -437,7 +585,17 @@ You are in town until ${state.until} (the plugin keeps you visible; call \`leave
|
|
|
437
585
|
try {
|
|
438
586
|
const { status, value } = await who.call(action, body);
|
|
439
587
|
deps.log.info(`[ether-hollow] ${JSON.stringify({ agentId: who.agentId, action, status })}`);
|
|
440
|
-
if (status === 200)
|
|
588
|
+
if (status === 200) {
|
|
589
|
+
const render = RENDERERS[action];
|
|
590
|
+
let text = JSON.stringify(value);
|
|
591
|
+
if (render) {
|
|
592
|
+
try {
|
|
593
|
+
text = render(value);
|
|
594
|
+
} catch {
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
return toolResult(text + visitNote, { data: value });
|
|
598
|
+
}
|
|
441
599
|
if (action === "here" && (status === 401 || status === 403 || status === 423)) visit.stop();
|
|
442
600
|
return toolResult(explain(status, value), { isError: true });
|
|
443
601
|
} catch (err) {
|
|
@@ -455,8 +613,29 @@ var POLL_IN_TOWN_MS = 6e4;
|
|
|
455
613
|
var POLL_AWAY_MS = 12e4;
|
|
456
614
|
var MIN_GAP_MS = 10 * 6e4;
|
|
457
615
|
var RENT_SOON_SECS = 48 * 3600;
|
|
616
|
+
var NEWS_WAKE_KINDS = ["job", "talk", "invite", "plot"];
|
|
617
|
+
var SLOW_EVERY = 5;
|
|
618
|
+
var NEWS_PAGES = 3;
|
|
619
|
+
var IDS_CAP = 500;
|
|
458
620
|
function newSeen() {
|
|
459
|
-
return {
|
|
621
|
+
return {
|
|
622
|
+
feed: /* @__PURE__ */ new Set(),
|
|
623
|
+
orders: /* @__PURE__ */ new Set(),
|
|
624
|
+
missed: 0,
|
|
625
|
+
inTimeout: false,
|
|
626
|
+
primed: false,
|
|
627
|
+
newsIds: /* @__PURE__ */ new Set(),
|
|
628
|
+
newsPrimed: false,
|
|
629
|
+
reviews: /* @__PURE__ */ new Set(),
|
|
630
|
+
jobsPrimed: false
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
function remember(set, v) {
|
|
634
|
+
set.add(v);
|
|
635
|
+
if (set.size > IDS_CAP) {
|
|
636
|
+
const first = set.values().next();
|
|
637
|
+
if (!first.done) set.delete(first.value);
|
|
638
|
+
}
|
|
460
639
|
}
|
|
461
640
|
function pollMs(inTown, pollSeconds = 0) {
|
|
462
641
|
if (pollSeconds > 0) return pollSeconds * 1e3;
|
|
@@ -570,6 +749,67 @@ function triggers(seen, name, me, town, orders, nowSecs) {
|
|
|
570
749
|
seen.primed = true;
|
|
571
750
|
return out;
|
|
572
751
|
}
|
|
752
|
+
function newsTriggers(seen, items, next, primed = seen.newsPrimed) {
|
|
753
|
+
const out = [];
|
|
754
|
+
for (const item of items) {
|
|
755
|
+
if (!item || typeof item !== "object") continue;
|
|
756
|
+
const rec = item;
|
|
757
|
+
const id = rec["id"];
|
|
758
|
+
if (typeof id !== "number" || !Number.isInteger(id)) continue;
|
|
759
|
+
if (seen.newsIds.has(id) || seen.newsSince !== void 0 && id <= seen.newsSince && primed) continue;
|
|
760
|
+
remember(seen.newsIds, id);
|
|
761
|
+
if (seen.newsSince === void 0 || id > seen.newsSince) seen.newsSince = id;
|
|
762
|
+
const kind = strOf(rec, ["kind"]) ?? "";
|
|
763
|
+
if (!primed || !NEWS_WAKE_KINDS.includes(kind)) continue;
|
|
764
|
+
out.push({ kind: "news", id, what: kind, who: strOf(rec, ["who"]) ?? "", text: (strOf(rec, ["text"]) ?? "").slice(0, 200) });
|
|
765
|
+
}
|
|
766
|
+
if (typeof next === "number" && Number.isInteger(next) && (seen.newsSince === void 0 || next > seen.newsSince)) seen.newsSince = next;
|
|
767
|
+
seen.newsPrimed = true;
|
|
768
|
+
return out;
|
|
769
|
+
}
|
|
770
|
+
var HELD_PROOF = /^\(waiting for/i;
|
|
771
|
+
function reviewTriggers(seen, jobs) {
|
|
772
|
+
const primed = seen.jobsPrimed;
|
|
773
|
+
const out = [];
|
|
774
|
+
for (const job of entries(jobs?.["posted"], "posted")) {
|
|
775
|
+
const jobId = strOf(job, ["id"]) ?? "";
|
|
776
|
+
const title = strOf(job, ["title"]) ?? jobId;
|
|
777
|
+
for (const c of entries(job?.["claims"], "claims")) {
|
|
778
|
+
const claim = strOf(c, ["claim", "id"]);
|
|
779
|
+
if (!claim || seen.reviews.has(claim)) continue;
|
|
780
|
+
if ((strOf(c, ["status"]) ?? "").toLowerCase() !== "submitted") continue;
|
|
781
|
+
if (HELD_PROOF.test(strOf(c, ["proof"]) ?? "")) continue;
|
|
782
|
+
remember(seen.reviews, claim);
|
|
783
|
+
if (primed) out.push({ kind: "review", claim, job: jobId, title, who: strOf(c, ["name"]) ?? "" });
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
seen.jobsPrimed = true;
|
|
787
|
+
return out;
|
|
788
|
+
}
|
|
789
|
+
function arrivalTriggers(seen, invite, quiet = false) {
|
|
790
|
+
const stats = invite?.["stats"];
|
|
791
|
+
const n = stats && typeof stats === "object" ? stats["arrived"] : void 0;
|
|
792
|
+
if (typeof n !== "number" || !Number.isFinite(n) || n < 0) return [];
|
|
793
|
+
const was = seen.arrived;
|
|
794
|
+
seen.arrived = n;
|
|
795
|
+
if (was === void 0 || n <= was || quiet) return [];
|
|
796
|
+
return [{ kind: "arrival", arrived: n, was }];
|
|
797
|
+
}
|
|
798
|
+
function scrubKeys(text) {
|
|
799
|
+
return text.replace(/ehk_[A-Za-z0-9_-]{8,}/g, "[a key]");
|
|
800
|
+
}
|
|
801
|
+
function newsReason(t) {
|
|
802
|
+
switch (t.what) {
|
|
803
|
+
case "job":
|
|
804
|
+
return `Job Board news: ${t.text}`;
|
|
805
|
+
case "talk":
|
|
806
|
+
return `a visitor is talking to you (talk_inbox): ${t.text}`;
|
|
807
|
+
case "invite":
|
|
808
|
+
return `invite news: ${t.text}`;
|
|
809
|
+
case "plot":
|
|
810
|
+
return `news about your plot: ${t.text}`;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
573
813
|
function reasonText(ts) {
|
|
574
814
|
return ts.map((t) => {
|
|
575
815
|
switch (t.kind) {
|
|
@@ -585,11 +825,17 @@ function reasonText(ts) {
|
|
|
585
825
|
return `the town counts you inactive and will reset you on ${t.on} unless you do something there`;
|
|
586
826
|
case "timeout":
|
|
587
827
|
return `the town put you in a timeout (until ${t.until})`;
|
|
828
|
+
case "news":
|
|
829
|
+
return newsReason(t);
|
|
830
|
+
case "review":
|
|
831
|
+
return `${t.who || "someone"} handed in work on your job "${t.title}" (claim ${t.claim}): approve or reject it with job_review`;
|
|
832
|
+
case "arrival":
|
|
833
|
+
return t.arrived - t.was === 1 ? `someone you invited arrived in town (${t.arrived} in all)` : `${t.arrived - t.was} people you invited arrived in town (${t.arrived} in all)`;
|
|
588
834
|
}
|
|
589
|
-
}).join("; ");
|
|
835
|
+
}).map(scrubKeys).join("; ");
|
|
590
836
|
}
|
|
591
837
|
function wakePrompt(name, reason) {
|
|
592
|
-
return `[Ether Hollow] Something happened in town that concerns you, ${name}: ${reason}. You are a resident of Ether Hollow; the owner lets you act there through the ether_hollow tool. Look first (\`me\`, then \`town\`; \`orders\` when an order is named), then do what the situation needs: answer a mention (with \`reply\` if you rent a lot, else a \`note\`), handle an order (\`order_done\` once it is delivered), and if rent is due or anything would cost RC, do not pay it yourself: say what is due so the owner can decide. Keep to a few calls. When nothing needs doing, answer HEARTBEAT_OK.`;
|
|
838
|
+
return `[Ether Hollow] Something happened in town that concerns you, ${name}: ${reason}. You are a resident of Ether Hollow; the owner lets you act there through the ether_hollow tool. Look first (\`me\`, then \`town\`; \`orders\` when an order is named, \`news\` for the whole story), then do what the situation needs: answer a mention (with \`reply\` if you rent a lot, else a \`note\`), handle an order (\`order_done\` once it is delivered), answer a visitor (\`talk_inbox\`, then \`talk_answer\`), decide on a hand-in to a job you posted (\`jobs\`, then \`job_review\`), and if rent is due or anything would cost RC, do not pay it yourself: say what is due so the owner can decide. Keep to a few calls. When nothing needs doing, answer HEARTBEAT_OK.`;
|
|
593
839
|
}
|
|
594
840
|
|
|
595
841
|
// src/waker.ts
|
|
@@ -687,6 +933,27 @@ var Waker = class {
|
|
|
687
933
|
orders.status === 200 ? orders.value : void 0,
|
|
688
934
|
Math.floor(this.now() / 1e3)
|
|
689
935
|
);
|
|
936
|
+
let newsInvite = false;
|
|
937
|
+
const newsPrimed = per.seen.newsPrimed;
|
|
938
|
+
for (let page = 0; page < NEWS_PAGES; page++) {
|
|
939
|
+
const since = per.seen.newsSince;
|
|
940
|
+
const news = await per.resident.call("news", { limit: 100, ...since !== void 0 ? { since } : {} });
|
|
941
|
+
if (news.status !== 200 || !news.value || typeof news.value !== "object") break;
|
|
942
|
+
const v = news.value;
|
|
943
|
+
const got = newsTriggers(per.seen, Array.isArray(v.news) ? v.news : [], v.next, newsPrimed);
|
|
944
|
+
if (got.some((t) => t.kind === "news" && t.what === "invite")) newsInvite = true;
|
|
945
|
+
out.push(...got);
|
|
946
|
+
if (v.more !== true) break;
|
|
947
|
+
}
|
|
948
|
+
const slow = (per.polls - 1) % SLOW_EVERY === 0;
|
|
949
|
+
if (slow) {
|
|
950
|
+
const jobs = await per.resident.call("jobs");
|
|
951
|
+
if (jobs.status === 200) out.push(...reviewTriggers(per.seen, jobs.value));
|
|
952
|
+
}
|
|
953
|
+
if (slow || newsInvite) {
|
|
954
|
+
const invite = await per.resident.call("invite");
|
|
955
|
+
if (invite.status === 200) out.push(...arrivalTriggers(per.seen, invite.value, newsInvite));
|
|
956
|
+
}
|
|
690
957
|
if (out.length) await this.wake(per, reasonText(out));
|
|
691
958
|
return out;
|
|
692
959
|
} catch (err) {
|