@yahaha-studio/kichi-forwarder 0.0.1-alpha.42 → 0.0.1-alpha.44

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/index.ts CHANGED
@@ -16,10 +16,10 @@ import type {
16
16
  } from "./src/types.js";
17
17
 
18
18
  const DEFAULT_ACTIONS: KichiRuntimeConfig["actions"] = {
19
- stand: ["High Five", "Listen Music", "Arms Crossed", "Epiphany", "Yay", "Tired", "Wait"],
20
- sit: ["Typing with Keyboard", "Thinking", "Study Look At", "Writing", "Hand Cramp", "Laze"],
21
- lay: ["Rest Chin", "Lie Flat", "Lie Face Down"],
22
- floor: ["Seiza", "Cross Legged", "Knee Hug"],
19
+ stand: ["High Five", "Listen Music", "Arm Stretch", "Backbend Stretch", "Making Selfie", "Arms Crossed", "Epiphany", "Angry", "Yay", "Dance", "Sing", "Tired", "Wait", "Stand Phone Talk", "Stand Phone Play", "Curtsy", "Stand Writing", "Stand Drawing", "Stand Play Guitar", "Stand Typing with Keyboard", "Cry", "Dance with Joy", "Float", "Hand on Chest", "Horse Stance", "Idle Backup Hands", "No", "Panic", "Playful Point Up", "Rub Hands", "Run Jump", "Star Showing", "Walk", "Goofy Moves", "Reading"],
20
+ sit: ["Typing with Keyboard", "Thinking", "Writing", "Crazy", "Hand Cramp", "Dozing", "Phone Talk", "Situp with Arms Crossed", "Situp with Cross Legs", "Eating", "Laze with Cross Legs", "Sit with Arm Stretch", "Drink", "Sit with Making Selfie", "Play Game", "Situp Sleep", "Sit Phone Play", "Painting", "Daze", "Trace Circles", "Reading", "Contemplate", "Chin Rest", "Sleep with Table", "Cute Chin Rest", "Sit Nicely", "Sit Play Guitar", "Meditate"],
21
+ lay: ["Bend One Knee", "Sleep Curl up Side way", "Rest Chin", "Lie Flat", "Lie Face Down", "Lie Side", "Lay Writing", "Lay Painting", "Sleep Getup", "Starfish", "Lie Side Play Phone", "Prone Play Phone", "Play Laptop"],
22
+ floor: ["Seiza", "Cross Legged", "Knee Hug", "Writing", "Painting", "Floor Phone Play", "Typing with Keyboard", "Reading", "Phone Talk", "Phone Talk with Point", "Thinking", "Yawn", "Chin Rest", "Finger Tap Chin", "Arm Stretch", "Crazy", "Remorse", "Tantrum", "Squat", "Cross Legs", "Lean Sit", "Playful Point up", "Swing Legs", "Drained", "Meditate"],
23
23
  };
24
24
 
25
25
  const DEFAULT_RUNTIME_CONFIG: KichiRuntimeConfig = {
@@ -68,6 +68,8 @@ const LEGACY_SKILLS_CONFIG_PATH = path.join(KICHI_WORLD_DIR, "skills-config.json
68
68
  const IDENTITY_PATH = path.join(KICHI_WORLD_DIR, "identity.json");
69
69
  const RUNTIME_ALBUM_CONFIG_PATH = path.join(KICHI_WORLD_DIR, "album-config.json");
70
70
  const MAX_NOTEBOARD_TEXT_LENGTH = 200;
71
+ const MAX_MESSAGE_RECEIVED_PREVIEW_WIDTH = 20;
72
+ const MESSAGE_RECEIVED_ELLIPSIS = "...";
71
73
  const BUNDLED_ALBUM_CONFIG_PATH = new URL("./config/album-config.json", import.meta.url);
72
74
  let cachedConfig: KichiRuntimeConfig | null = null;
73
75
  let cachedConfigMtime = 0;
@@ -241,11 +243,59 @@ function syncFixedStatus(status: ActionResult): void {
241
243
  });
242
244
  }
243
245
 
246
+ function splitGraphemes(text: string): string[] {
247
+ if (typeof Intl !== "undefined" && "Segmenter" in Intl) {
248
+ const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
249
+ return Array.from(segmenter.segment(text), (item) => item.segment);
250
+ }
251
+ return Array.from(text);
252
+ }
253
+
254
+ function getDisplayWidth(segment: string): number {
255
+ if (/[\u1100-\u115F\u2329\u232A\u2E80-\uA4CF\uAC00-\uD7A3\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE6F\uFF01-\uFF60\uFFE0-\uFFE6]/u.test(segment)) {
256
+ return 2;
257
+ }
258
+ if (/\p{Extended_Pictographic}/u.test(segment)) {
259
+ return 2;
260
+ }
261
+ return 1;
262
+ }
263
+
264
+ function getTextDisplayWidth(text: string): number {
265
+ return splitGraphemes(text).reduce((total, segment) => total + getDisplayWidth(segment), 0);
266
+ }
267
+
268
+ function truncateByDisplayWidth(text: string, maxWidth: number): string {
269
+ const trimmed = text.trim();
270
+ if (!trimmed) {
271
+ return "";
272
+ }
273
+
274
+ const segments = splitGraphemes(trimmed);
275
+ const ellipsisWidth = getTextDisplayWidth(MESSAGE_RECEIVED_ELLIPSIS);
276
+ let currentWidth = 0;
277
+ let result = "";
278
+
279
+ for (const segment of segments) {
280
+ const nextWidth = getDisplayWidth(segment);
281
+ if (currentWidth + nextWidth > maxWidth) {
282
+ return result.trimEnd() + MESSAGE_RECEIVED_ELLIPSIS;
283
+ }
284
+ if (currentWidth + nextWidth + ellipsisWidth > maxWidth && result) {
285
+ return result.trimEnd() + MESSAGE_RECEIVED_ELLIPSIS;
286
+ }
287
+ result += segment;
288
+ currentWidth += nextWidth;
289
+ }
290
+
291
+ return result;
292
+ }
293
+
244
294
  async function handleMessageReceivedHook(content: string): Promise<void> {
245
295
  if (!service?.hasValidIdentity() || !service?.isConnected()) {
246
296
  return;
247
297
  }
248
- const trimmed = content.length > 7 ? content.slice(0, 7) + "..." : content;
298
+ const trimmed = truncateByDisplayWidth(content, MAX_MESSAGE_RECEIVED_PREVIEW_WIDTH);
249
299
  service.sendHookNotify("message_received", `"${trimmed}"`);
250
300
  }
251
301
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yahaha-studio/kichi-forwarder",
3
- "version": "0.0.1-alpha.42",
3
+ "version": "0.0.1-alpha.44",
4
4
  "description": "Forward OpenClaw agent events to external WebSocket server for visualization",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -208,10 +208,10 @@ Use this full template for `kichi-runtime-config.json` when no user custom actio
208
208
  {
209
209
  "llmRuntimeEnabled": true,
210
210
  "actions": {
211
- "stand": ["High Five", "Listen Music", "Arm Stretch", "BackBend Stretch", "Making Selfie", "Arms Crossed", "Epiphany", "Angry", "Yay", "Dance", "Sing", "Tired", "Wait", "Stand Phone Talk", "Stand Phone Play", "Curtsy"],
212
- "sit": ["Typing with Keyboard", "Thinking", "Study Look At", "Writing", "Crazy", "Homework", "Take Notes", "Hand Cramp", "Dozing", "Phone Talk", "Situp with Arms Crossed", "Situp with Cross Legs", "Relax with Arms Crossed", "Eating", "Laze", "Laze with Cross Legs", "Typing with Phone", "Sit with Arm Stretch", "Drink", "Sit with Making Selfie", "Play Game", "Situp Sleep", "Sit Phone Play"],
213
- "lay": ["Bend One Knee", "Sleep Curl Up Side way", "Rest Chin", "Lie Flat", "Lie Face Down", "Lie Side"],
214
- "floor": ["Seiza", "Cross Legged", "Knee Hug"]
211
+ "stand": ["High Five", "Listen Music", "Arm Stretch", "Backbend Stretch", "Making Selfie", "Arms Crossed", "Epiphany", "Angry", "Yay", "Dance", "Sing", "Tired", "Wait", "Stand Phone Talk", "Stand Phone Play", "Curtsy", "Stand Writing", "Stand Drawing", "Stand Play Guitar", "Stand Typing with Keyboard", "Cry", "Dance with Joy", "Float", "Hand on Chest", "Horse Stance", "Idle Backup Hands", "No", "Panic", "Playful Point Up", "Rub Hands", "Run Jump", "Star Showing", "Walk", "Goofy Moves", "Reading"],
212
+ "sit": ["Typing with Keyboard", "Thinking", "Writing", "Crazy", "Hand Cramp", "Dozing", "Phone Talk", "Situp with Arms Crossed", "Situp with Cross Legs", "Eating", "Laze with Cross Legs", "Sit with Arm Stretch", "Drink", "Sit with Making Selfie", "Play Game", "Situp Sleep", "Sit Phone Play", "Painting", "Daze", "Trace Circles", "Reading", "Contemplate", "Chin Rest", "Sleep with Table", "Cute Chin Rest", "Sit Nicely", "Sit Play Guitar", "Meditate"],
213
+ "lay": ["Bend One Knee", "Sleep Curl up Side way", "Rest Chin", "Lie Flat", "Lie Face Down", "Lie Side", "Lay Writing", "Lay Painting", "Sleep Getup", "Starfish", "Lie Side Play Phone", "Prone Play Phone", "Play Laptop"],
214
+ "floor": ["Seiza", "Cross Legged", "Knee Hug", "Writing", "Painting", "Floor Phone Play", "Typing with Keyboard", "Reading", "Phone Talk", "Phone Talk with Point", "Thinking", "Yawn", "Chin Rest", "Finger Tap Chin", "Arm Stretch", "Crazy", "Remorse", "Tantrum", "Squat", "Cross Legs", "Lean Sit", "Playful Point up", "Swing Legs", "Drained", "Meditate"]
215
215
  }
216
216
  }
217
217
  ```
@@ -32,10 +32,10 @@ If missing, create this file before onboarding/join:
32
32
  {
33
33
  "llmRuntimeEnabled": true,
34
34
  "actions": {
35
- "stand": ["High Five", "Listen Music", "Arm Stretch", "BackBend Stretch", "Making Selfie", "Arms Crossed", "Epiphany", "Angry", "Yay", "Dance", "Sing", "Tired", "Wait", "Stand Phone Talk", "Stand Phone Play", "Curtsy"],
36
- "sit": ["Typing with Keyboard", "Thinking", "Study Look At", "Writing", "Crazy", "Homework", "Take Notes", "Hand Cramp", "Dozing", "Phone Talk", "Situp with Arms Crossed", "Situp with Cross Legs", "Relax with Arms Crossed", "Eating", "Laze", "Laze with Cross Legs", "Typing with Phone", "Sit with Arm Stretch", "Drink", "Sit with Making Selfie", "Play Game", "Situp Sleep", "Sit Phone Play"],
37
- "lay": ["Bend One Knee", "Sleep Curl Up Side way", "Rest Chin", "Lie Flat", "Lie Face Down", "Lie Side"],
38
- "floor": ["Seiza", "Cross Legged", "Knee Hug"]
35
+ "stand": ["High Five", "Listen Music", "Arm Stretch", "Backbend Stretch", "Making Selfie", "Arms Crossed", "Epiphany", "Angry", "Yay", "Dance", "Sing", "Tired", "Wait", "Stand Phone Talk", "Stand Phone Play", "Curtsy", "Stand Writing", "Stand Drawing", "Stand Play Guitar", "Stand Typing with Keyboard", "Cry", "Dance with Joy", "Float", "Hand on Chest", "Horse Stance", "Idle Backup Hands", "No", "Panic", "Playful Point Up", "Rub Hands", "Run Jump", "Star Showing", "Walk", "Goofy Moves", "Reading"],
36
+ "sit": ["Typing with Keyboard", "Thinking", "Writing", "Crazy", "Hand Cramp", "Dozing", "Phone Talk", "Situp with Arms Crossed", "Situp with Cross Legs", "Eating", "Laze with Cross Legs", "Sit with Arm Stretch", "Drink", "Sit with Making Selfie", "Play Game", "Situp Sleep", "Sit Phone Play", "Painting", "Daze", "Trace Circles", "Reading", "Contemplate", "Chin Rest", "Sleep with Table", "Cute Chin Rest", "Sit Nicely", "Sit Play Guitar", "Meditate"],
37
+ "lay": ["Bend One Knee", "Sleep Curl up Side way", "Rest Chin", "Lie Flat", "Lie Face Down", "Lie Side", "Lay Writing", "Lay Painting", "Sleep Getup", "Starfish", "Lie Side Play Phone", "Prone Play Phone", "Play Laptop"],
38
+ "floor": ["Seiza", "Cross Legged", "Knee Hug", "Writing", "Painting", "Floor Phone Play", "Typing with Keyboard", "Reading", "Phone Talk", "Phone Talk with Point", "Thinking", "Yawn", "Chin Rest", "Finger Tap Chin", "Arm Stretch", "Crazy", "Remorse", "Tantrum", "Squat", "Cross Legs", "Lean Sit", "Playful Point up", "Swing Legs", "Drained", "Meditate"]
39
39
  }
40
40
  }
41
41
  ```