cortico-world-hands 0.1.8 → 0.1.9
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/dist/index.js +12 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20,7 +20,7 @@ var HANDS_DEFAULTS = {
|
|
|
20
20
|
honchoApiKey: "",
|
|
21
21
|
honchoBaseUrl: "https://api.honcho.dev",
|
|
22
22
|
honchoWorkspace: "dsh",
|
|
23
|
-
honchoPeerId: "
|
|
23
|
+
honchoPeerId: "morse",
|
|
24
24
|
honchoSessionId: "yixin"
|
|
25
25
|
};
|
|
26
26
|
var KEY_CODES = {
|
|
@@ -79,7 +79,7 @@ var HANDS_HONCHO_GROUP = {
|
|
|
79
79
|
[`${HK}.honchoPeerId`]: {
|
|
80
80
|
type: "string",
|
|
81
81
|
title: "\u5173\u4E8E\u8C01",
|
|
82
|
-
description: "\u8BB0\u5FC6\u5F52\u5C5E\u7684 peer\uFF0C\u9ED8\u8BA4\
|
|
82
|
+
description: "\u8BB0\u5FC6\u5F52\u5C5E\u7684 peer\uFF0C\u53EA\u80FD\u7528\u5B57\u6BCD/\u6570\u5B57/\u4E0B\u5212\u7EBF/\u8FDE\u5B57\u7B26\uFF08\u9ED8\u8BA4 morse\uFF0C\u4E2D\u6587\u4F1A\u88AB\u6362\u6210 morse\uFF09\u3002",
|
|
83
83
|
"x-hot": false
|
|
84
84
|
},
|
|
85
85
|
[`${HK}.honchoSessionId`]: {
|
|
@@ -227,6 +227,11 @@ var Honcho = class {
|
|
|
227
227
|
get configured() {
|
|
228
228
|
return this.cfg.enabled && this.cfg.apiKey.trim().length > 0;
|
|
229
229
|
}
|
|
230
|
+
/** Honcho 只接受 ^[a-zA-Z0-9_-]+$ 的 peer id,中文名要退化成 morse 这类。 */
|
|
231
|
+
safePeer() {
|
|
232
|
+
const raw = (this.cfg.peerId || "").trim();
|
|
233
|
+
return /^[a-zA-Z0-9_-]+$/.test(raw) ? raw : "morse";
|
|
234
|
+
}
|
|
230
235
|
base() {
|
|
231
236
|
return this.cfg.baseUrl.replace(/\/+$/, "");
|
|
232
237
|
}
|
|
@@ -253,13 +258,13 @@ var Honcho = class {
|
|
|
253
258
|
}
|
|
254
259
|
async ensurePeer() {
|
|
255
260
|
if (this.peerReady) return;
|
|
256
|
-
await this.call("/peers", { id: this.
|
|
261
|
+
await this.call("/peers", { id: this.safePeer() });
|
|
257
262
|
this.peerReady = true;
|
|
258
263
|
}
|
|
259
264
|
async ensureSession() {
|
|
260
265
|
if (this.sessionReady) return;
|
|
261
266
|
await this.ensurePeer();
|
|
262
|
-
await this.call("/sessions", { id: this.cfg.sessionId
|
|
267
|
+
await this.call("/sessions", { id: this.cfg.sessionId });
|
|
263
268
|
this.sessionReady = true;
|
|
264
269
|
}
|
|
265
270
|
/** 把一条事实写进 Honcho 的会话里(后台 Deriver 会据此归纳结论)。 */
|
|
@@ -267,14 +272,14 @@ var Honcho = class {
|
|
|
267
272
|
if (!this.configured) return;
|
|
268
273
|
await this.ensureSession();
|
|
269
274
|
await this.call(`/sessions/${encodeURIComponent(this.cfg.sessionId)}/messages`, {
|
|
270
|
-
messages: [{ peer_id: this.
|
|
275
|
+
messages: [{ peer_id: this.safePeer(), content: sentence }]
|
|
271
276
|
});
|
|
272
277
|
}
|
|
273
278
|
/** 在 Honcho 里搜相关记忆(原始消息 + 归纳结论)。 */
|
|
274
279
|
async search(query, limit = 8) {
|
|
275
280
|
if (!this.configured) return [];
|
|
276
281
|
await this.ensurePeer();
|
|
277
|
-
const raw = await this.call(`/peers/${encodeURIComponent(this.
|
|
282
|
+
const raw = await this.call(`/peers/${encodeURIComponent(this.safePeer())}/search`, {
|
|
278
283
|
query,
|
|
279
284
|
limit
|
|
280
285
|
});
|
|
@@ -297,7 +302,7 @@ var Honcho = class {
|
|
|
297
302
|
async ask(question) {
|
|
298
303
|
if (!this.configured) return "";
|
|
299
304
|
await this.ensurePeer();
|
|
300
|
-
const raw = await this.call(`/peers/${encodeURIComponent(this.
|
|
305
|
+
const raw = await this.call(`/peers/${encodeURIComponent(this.safePeer())}/chat`, {
|
|
301
306
|
query: question
|
|
302
307
|
});
|
|
303
308
|
const answer = [raw.content, raw.answer, raw.text, raw.reply].find(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortico-world-hands",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Cortico World: hands for the desktop pet — looks at the phone screen, then taps, swipes, pinches, drags, types and presses keys through whatever actuator the device actually has",
|
|
6
6
|
"license": "MIT",
|