agentshire 1.0.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/CHANGELOG.md +36 -0
- package/LICENSE +21 -0
- package/README.md +437 -0
- package/README.zh-CN.md +441 -0
- package/ROADMAP.md +207 -0
- package/THIRD_PARTY_NOTICES.md +49 -0
- package/VISION.md +101 -0
- package/index.ts +386 -0
- package/openclaw.plugin.json +27 -0
- package/package.json +100 -0
- package/src/bridge/AGENTS.md +136 -0
- package/src/bridge/ActivityStream.ts +184 -0
- package/src/bridge/CitizenManager.ts +280 -0
- package/src/bridge/DirectorBridge.ts +1076 -0
- package/src/bridge/EventTranslator.ts +142 -0
- package/src/bridge/NpcEventQueue.ts +61 -0
- package/src/bridge/ReconnectManager.ts +42 -0
- package/src/bridge/RouteManager.ts +270 -0
- package/src/bridge/StateTracker.ts +100 -0
- package/src/bridge/ToolVfxMapper.ts +94 -0
- package/src/bridge/__tests__/ActivityStream.test.ts +156 -0
- package/src/bridge/__tests__/CitizenManager.test.ts +174 -0
- package/src/bridge/__tests__/EventTranslator.test.ts +292 -0
- package/src/bridge/__tests__/NpcEventQueue.test.ts +92 -0
- package/src/bridge/__tests__/RouteManager.test.ts +106 -0
- package/src/bridge/data/route-config.json +36 -0
- package/src/bridge/data/route-config.ts +19 -0
- package/src/bridge/implicit-chat.ts +192 -0
- package/src/bridge/index.ts +12 -0
- package/src/contracts/agent-state.ts +87 -0
- package/src/contracts/agui.ts +212 -0
- package/src/contracts/chat.ts +67 -0
- package/src/contracts/events.ts +170 -0
- package/src/contracts/index.ts +71 -0
- package/src/contracts/media.ts +77 -0
- package/src/contracts/registry.ts +32 -0
- package/src/plugin/AGENTS.md +192 -0
- package/src/plugin/__tests__/editor-serve-megapack.test.ts +150 -0
- package/src/plugin/__tests__/hook-translator.test.ts +197 -0
- package/src/plugin/auto-config.ts +131 -0
- package/src/plugin/channel.ts +399 -0
- package/src/plugin/chat-asset-resolver.ts +75 -0
- package/src/plugin/chat-session-watcher.ts +98 -0
- package/src/plugin/citizen-agent-manager.ts +178 -0
- package/src/plugin/citizen-chat-router.ts +83 -0
- package/src/plugin/citizen-workshop-manager.ts +96 -0
- package/src/plugin/custom-asset-manager.ts +250 -0
- package/src/plugin/editor-serve.ts +1368 -0
- package/src/plugin/group-discussion.ts +223 -0
- package/src/plugin/hook-translator.ts +202 -0
- package/src/plugin/llm-agent-proxy.ts +193 -0
- package/src/plugin/outbound-adapter.ts +187 -0
- package/src/plugin/paths.ts +33 -0
- package/src/plugin/plan-manager.ts +594 -0
- package/src/plugin/runtime.ts +9 -0
- package/src/plugin/session-history.ts +838 -0
- package/src/plugin/session-log-watcher.ts +221 -0
- package/src/plugin/soul-prompt-template.ts +290 -0
- package/src/plugin/subagent-tracker.ts +205 -0
- package/src/plugin/tools.ts +493 -0
- package/src/plugin/town-session.ts +40 -0
- package/src/plugin/ws-server.ts +680 -0
- package/src/town-souls.ts +134 -0
- package/town-frontend/dist/assets/CustomAssetStore-oi8aIurt.js +2 -0
- package/town-frontend/dist/assets/GLTFLoader-BA5RqSME.js +3804 -0
- package/town-frontend/dist/assets/OrbitControls-ZmySp9sQ.js +2 -0
- package/town-frontend/dist/assets/SettingsPanel-BO52reJe.js +2 -0
- package/town-frontend/dist/assets/SkeletonUtils-BCVmgslc.js +2 -0
- package/town-frontend/dist/assets/SkillLearnCard-Dk38iDpy.js +6 -0
- package/town-frontend/dist/assets/TopicSetupPanel-DLaLHB_Z.js +2 -0
- package/town-frontend/dist/assets/Trap-Bold-CT0JBE39.woff2 +0 -0
- package/town-frontend/dist/assets/Trap-SemiBold-R4_-Ld0j.woff2 +0 -0
- package/town-frontend/dist/assets/WeatherSystem-Cb3BvHes.js +550 -0
- package/town-frontend/dist/assets/avatars/char-female-a.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-female-b.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-female-c.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-female-d.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-female-e.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-female-f.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-male-a.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-male-b.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-male-c.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-male-d.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-male-e.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-male-f.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-beaver.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-bee.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-bunny.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-cat.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-caterpillar.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-chick.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-cow.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-crab.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-deer.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-dog.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-elephant.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-fish.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-fox.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-giraffe.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-hog.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-koala.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-lion.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-monkey.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-panda.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-parrot.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-penguin.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-pig.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-polar.webp +0 -0
- package/town-frontend/dist/assets/avatars/char-pet-tiger.webp +0 -0
- package/town-frontend/dist/assets/character-catalog-DSmLtlNC.js +2 -0
- package/town-frontend/dist/assets/citizenEditor-DubGSJOQ.js +296 -0
- package/town-frontend/dist/assets/command-parser-BUd15Bmv.js +12 -0
- package/town-frontend/dist/assets/editor-B5QO0OtX.js +258 -0
- package/town-frontend/dist/assets/editor-Bk8g1NCD.css +1 -0
- package/town-frontend/dist/assets/index-BWfrufil.js +2 -0
- package/town-frontend/dist/assets/index-faS20RJk.js +6 -0
- package/town-frontend/dist/assets/logo-DJI6EtST.png +0 -0
- package/town-frontend/dist/assets/logo-title-AdKPZX5E.png +0 -0
- package/town-frontend/dist/assets/main-CqsN43aT.js +224 -0
- package/town-frontend/dist/assets/main-D7neuy3w.css +1 -0
- package/town-frontend/dist/assets/models/buildings/base.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/base.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/bench.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/bench.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/box_A.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/box_A.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/box_B.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/box_B.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/building_A.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/building_A.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/building_A_withoutBase.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/building_A_withoutBase.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/building_B.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/building_B.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/building_B_withoutBase.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/building_B_withoutBase.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/building_C.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/building_C.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/building_C_withoutBase.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/building_C_withoutBase.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/building_D.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/building_D.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/building_D_withoutBase.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/building_D_withoutBase.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/building_E.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/building_E.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/building_E_withoutBase.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/building_E_withoutBase.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/building_F.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/building_F.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/building_F_withoutBase.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/building_F_withoutBase.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/building_G.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/building_G.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/building_G_withoutBase.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/building_G_withoutBase.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/building_H.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/building_H.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/building_H_withoutBase.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/building_H_withoutBase.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/bush.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/bush.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/car_hatchback.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/car_hatchback.gltf +442 -0
- package/town-frontend/dist/assets/models/buildings/car_police.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/car_police.gltf +442 -0
- package/town-frontend/dist/assets/models/buildings/car_sedan.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/car_sedan.gltf +442 -0
- package/town-frontend/dist/assets/models/buildings/car_stationwagon.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/car_stationwagon.gltf +442 -0
- package/town-frontend/dist/assets/models/buildings/car_taxi.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/car_taxi.gltf +442 -0
- package/town-frontend/dist/assets/models/buildings/citybits_texture.png +0 -0
- package/town-frontend/dist/assets/models/buildings/dumpster.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/dumpster.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/firehydrant.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/firehydrant.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/road_corner.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/road_corner.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/road_corner_curved.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/road_corner_curved.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/road_junction.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/road_junction.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/road_straight.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/road_straight.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/road_straight_crossing.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/road_straight_crossing.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/road_tsplit.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/road_tsplit.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/streetlight.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/streetlight.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/trafficlight_A.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/trafficlight_A.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/trafficlight_B.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/trafficlight_B.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/trafficlight_C.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/trafficlight_C.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/trash_A.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/trash_A.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/trash_B.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/trash_B.gltf +136 -0
- package/town-frontend/dist/assets/models/buildings/watertower.bin +0 -0
- package/town-frontend/dist/assets/models/buildings/watertower.gltf +136 -0
- package/town-frontend/dist/assets/models/characters/Textures/colormap.png +0 -0
- package/town-frontend/dist/assets/models/characters/character-female-a.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-female-b.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-female-c.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-female-d.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-female-e.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-female-f.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-male-a.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-male-b.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-male-c.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-male-d.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-male-e.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-male-f.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-beaver.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-bee.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-bunny.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-cat.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-caterpillar.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-chick.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-cow.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-crab.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-deer.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-dog.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-elephant.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-fish.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-fox.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-giraffe.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-hog.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-koala.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-lion.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-monkey.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-panda.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-parrot.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-penguin.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-pig.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-polar.glb +0 -0
- package/town-frontend/dist/assets/models/characters/character-pet-tiger.glb +0 -0
- package/town-frontend/dist/assets/models/characters/colormap.png +0 -0
- package/town-frontend/dist/assets/models/furniture/armchair.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/armchair.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/armchair_pillows.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/armchair_pillows.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/bed_double_A.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/bed_double_A.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/bed_double_B.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/bed_double_B.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/bed_single_A.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/bed_single_A.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/bed_single_B.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/bed_single_B.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/book_set.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/book_set.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/book_single.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/book_single.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/cabinet_medium.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/cabinet_medium.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/cabinet_medium_decorated.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/cabinet_medium_decorated.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/cabinet_small.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/cabinet_small.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/cabinet_small_decorated.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/cabinet_small_decorated.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/cactus_medium_A.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/cactus_medium_A.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/cactus_medium_B.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/cactus_medium_B.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/cactus_small_A.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/cactus_small_A.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/cactus_small_B.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/cactus_small_B.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/chair_A.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/chair_A.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/chair_A_wood.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/chair_A_wood.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/chair_B.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/chair_B.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/chair_B_wood.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/chair_B_wood.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/chair_C.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/chair_C.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/chair_stool.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/chair_stool.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/chair_stool_wood.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/chair_stool_wood.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/couch.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/couch.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/couch_pillows.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/couch_pillows.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/furniturebits_texture.png +0 -0
- package/town-frontend/dist/assets/models/furniture/lamp_standing.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/lamp_standing.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/lamp_table.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/lamp_table.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/pictureframe_large_A.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/pictureframe_large_A.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/pictureframe_large_B.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/pictureframe_large_B.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/pictureframe_medium.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/pictureframe_medium.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/pictureframe_small_A.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/pictureframe_small_A.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/pictureframe_small_B.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/pictureframe_small_B.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/pictureframe_small_C.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/pictureframe_small_C.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/pictureframe_standing_A.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/pictureframe_standing_A.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/pictureframe_standing_B.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/pictureframe_standing_B.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/pillow_A.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/pillow_A.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/pillow_B.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/pillow_B.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/rug_oval_A.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/rug_oval_A.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/rug_oval_B.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/rug_oval_B.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/rug_rectangle_A.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/rug_rectangle_A.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/rug_rectangle_B.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/rug_rectangle_B.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/rug_rectangle_stripes_A.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/rug_rectangle_stripes_A.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/rug_rectangle_stripes_B.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/rug_rectangle_stripes_B.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/shelf_A_big.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/shelf_A_big.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/shelf_A_small.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/shelf_A_small.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/shelf_B_large.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/shelf_B_large.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/shelf_B_large_decorated.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/shelf_B_large_decorated.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/shelf_B_small.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/shelf_B_small.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/shelf_B_small_decorated.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/shelf_B_small_decorated.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/table_low.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/table_low.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/table_medium.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/table_medium.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/table_medium_long.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/table_medium_long.gltf +136 -0
- package/town-frontend/dist/assets/models/furniture/table_small.bin +0 -0
- package/town-frontend/dist/assets/models/furniture/table_small.gltf +136 -0
- package/town-frontend/dist/assets/models/props/bench.bin +0 -0
- package/town-frontend/dist/assets/models/props/bench.gltf +136 -0
- package/town-frontend/dist/assets/models/props/bush.bin +0 -0
- package/town-frontend/dist/assets/models/props/bush.gltf +136 -0
- package/town-frontend/dist/assets/models/props/capybara.glb +0 -0
- package/town-frontend/dist/assets/models/props/car_hatchback.bin +0 -0
- package/town-frontend/dist/assets/models/props/car_hatchback.gltf +442 -0
- package/town-frontend/dist/assets/models/props/car_sedan.bin +0 -0
- package/town-frontend/dist/assets/models/props/car_sedan.gltf +442 -0
- package/town-frontend/dist/assets/models/props/car_taxi.bin +0 -0
- package/town-frontend/dist/assets/models/props/car_taxi.gltf +442 -0
- package/town-frontend/dist/assets/models/props/citybits_texture.png +0 -0
- package/town-frontend/dist/assets/models/props/dumpster.bin +0 -0
- package/town-frontend/dist/assets/models/props/dumpster.gltf +136 -0
- package/town-frontend/dist/assets/models/props/firehydrant.bin +0 -0
- package/town-frontend/dist/assets/models/props/firehydrant.gltf +136 -0
- package/town-frontend/dist/assets/models/props/streetlight.bin +0 -0
- package/town-frontend/dist/assets/models/props/streetlight.gltf +136 -0
- package/town-frontend/dist/assets/models/props/trafficlight_A.bin +0 -0
- package/town-frontend/dist/assets/models/props/trafficlight_A.gltf +136 -0
- package/town-frontend/dist/assets/models/props/trash_A.bin +0 -0
- package/town-frontend/dist/assets/models/props/trash_A.gltf +136 -0
- package/town-frontend/dist/assets/models/props/watertower.bin +0 -0
- package/town-frontend/dist/assets/models/props/watertower.gltf +136 -0
- package/town-frontend/dist/assets/models/stage-deco/Flowers_1_D.glb +0 -0
- package/town-frontend/dist/assets/models/stage-deco/Flowers_2_B.glb +0 -0
- package/town-frontend/dist/assets/models/stage-deco/Grass_A_1.glb +0 -0
- package/town-frontend/dist/assets/models/stage-deco/Park_GrassHill_A.glb +0 -0
- package/town-frontend/dist/assets/models/stage-deco/Pebles_1_A_2.glb +0 -0
- package/town-frontend/dist/assets/music/bgm_day.mp3 +0 -0
- package/town-frontend/dist/assets/music/bgm_dusk.mp3 +0 -0
- package/town-frontend/dist/assets/music/bgm_night.mp3 +0 -0
- package/town-frontend/dist/assets/music/bgm_work.mp3 +0 -0
- package/town-frontend/dist/assets/office-whiteboard-idle-CyEwBrq_.webp +0 -0
- package/town-frontend/dist/assets/preview-B6hYEQij.js +2 -0
- package/town-frontend/dist/assets/town-BKesnERP.js +8888 -0
- package/town-frontend/dist/assets/town-BnswKsjF.css +1 -0
- package/town-frontend/dist/citizen-editor.html +166 -0
- package/town-frontend/dist/editor.html +227 -0
- package/town-frontend/dist/index.html +22 -0
- package/town-frontend/dist/preview.html +56 -0
- package/town-frontend/dist/town.html +165 -0
- package/town-frontend/dist/viewer.html +91 -0
- package/town-souls/CHEN.md +130 -0
- package/town-souls/CHENGZI.md +92 -0
- package/town-souls/CITIZEN_tpl.md +16 -0
- package/town-souls/DIANDIAN.md +92 -0
- package/town-souls/HAITANG.md +94 -0
- package/town-souls/QIQI.md +119 -0
- package/town-souls/SOUL.md +141 -0
- package/town-souls/SOUL_tpl.md +135 -0
- package/town-souls/XIAOLIE.md +107 -0
- package/town-souls/YAN.md +107 -0
- package/town-workspace/IDENTITY.md +5 -0
- package/town-workspace/SOUL.md +141 -0
- package/town-workspace/project-workflow.md +81 -0
- package/town-workspace/town-defaults.json +92 -0
- package/town-workspace/town-guide.md +45 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages independent citizen agents in openclaw.json agents.list.
|
|
3
|
+
* Creates workspace + SOUL.md for each citizen.
|
|
4
|
+
* No sub-agents — each citizen is a full independent agent.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, copyFileSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { stateDir } from "./paths.js";
|
|
11
|
+
|
|
12
|
+
export interface AgentChange {
|
|
13
|
+
action: "create" | "disable" | "update_soul";
|
|
14
|
+
citizenId: string;
|
|
15
|
+
citizenName: string;
|
|
16
|
+
agentId: string;
|
|
17
|
+
soulContent?: string;
|
|
18
|
+
specialty?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AgentChangeResult {
|
|
22
|
+
citizenId: string;
|
|
23
|
+
action: string;
|
|
24
|
+
success: boolean;
|
|
25
|
+
agentId?: string;
|
|
26
|
+
error?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getOpenClawConfigPath(): string {
|
|
30
|
+
return join(stateDir(), "openclaw.json");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getAgentWorkspacePath(agentId: string): string {
|
|
34
|
+
return join(stateDir(), `workspace-${agentId}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function loadOpenClawConfig(): any {
|
|
38
|
+
const configPath = getOpenClawConfigPath();
|
|
39
|
+
if (!existsSync(configPath)) throw new Error("openclaw.json not found");
|
|
40
|
+
return JSON.parse(readFileSync(configPath, "utf-8"));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function saveOpenClawConfig(cfg: any): void {
|
|
44
|
+
const configPath = getOpenClawConfigPath();
|
|
45
|
+
writeFileSync(configPath, JSON.stringify(cfg, null, 2) + "\n", "utf-8");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getPluginDir(): string {
|
|
49
|
+
return join(fileURLToPath(import.meta.url), "../../..");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getStewardWorkspaceDir(): string {
|
|
53
|
+
return join(stateDir(), "workspace-town-steward");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function syncSharedFiles(workspace: string): void {
|
|
57
|
+
const pluginDir = getPluginDir();
|
|
58
|
+
const stewardDir = getStewardWorkspaceDir();
|
|
59
|
+
const sharedFiles = ["town-guide.md", "town-defaults.json"];
|
|
60
|
+
for (const file of sharedFiles) {
|
|
61
|
+
const dst = join(workspace, file);
|
|
62
|
+
const stewardSrc = join(stewardDir, file);
|
|
63
|
+
const pluginSrc = join(pluginDir, "town-workspace", file);
|
|
64
|
+
const src = existsSync(stewardSrc) ? stewardSrc : pluginSrc;
|
|
65
|
+
if (existsSync(src)) {
|
|
66
|
+
copyFileSync(src, dst);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function writeIdentity(workspace: string, name: string, specialty?: string): void {
|
|
72
|
+
const lines = [
|
|
73
|
+
`# ${name}`,
|
|
74
|
+
"",
|
|
75
|
+
`- **Name:** ${name}`,
|
|
76
|
+
];
|
|
77
|
+
if (specialty) lines.push(`- **Role:** ${specialty}`);
|
|
78
|
+
if (specialty) lines.push(`- Vibe: ${specialty}`);
|
|
79
|
+
writeFileSync(join(workspace, "IDENTITY.md"), lines.join("\n") + "\n", "utf-8");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function createAgentWorkspace(agentId: string, soulContent: string, name: string, specialty?: string): void {
|
|
83
|
+
const workspace = getAgentWorkspacePath(agentId);
|
|
84
|
+
if (!existsSync(workspace)) mkdirSync(workspace, { recursive: true });
|
|
85
|
+
writeFileSync(join(workspace, "SOUL.md"), soulContent, "utf-8");
|
|
86
|
+
writeIdentity(workspace, name, specialty);
|
|
87
|
+
syncSharedFiles(workspace);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function updateSoulFile(agentId: string, soulContent: string, name: string, specialty?: string): void {
|
|
91
|
+
const workspace = getAgentWorkspacePath(agentId);
|
|
92
|
+
if (!existsSync(workspace)) mkdirSync(workspace, { recursive: true });
|
|
93
|
+
writeFileSync(join(workspace, "SOUL.md"), soulContent, "utf-8");
|
|
94
|
+
writeIdentity(workspace, name, specialty);
|
|
95
|
+
syncSharedFiles(workspace);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function addAgentToConfig(agentId: string, citizenName: string, specialty?: string): void {
|
|
99
|
+
const cfg = loadOpenClawConfig();
|
|
100
|
+
const agents: any[] = cfg.agents?.list ?? [];
|
|
101
|
+
if (agents.some((a: any) => a.id === agentId)) return;
|
|
102
|
+
|
|
103
|
+
if (!cfg.agents) cfg.agents = {};
|
|
104
|
+
if (!cfg.agents.list) cfg.agents.list = [];
|
|
105
|
+
const identity: Record<string, string> = { name: citizenName };
|
|
106
|
+
cfg.agents.list.push({
|
|
107
|
+
id: agentId,
|
|
108
|
+
name: citizenName,
|
|
109
|
+
workspace: getAgentWorkspacePath(agentId),
|
|
110
|
+
identity,
|
|
111
|
+
});
|
|
112
|
+
saveOpenClawConfig(cfg);
|
|
113
|
+
console.log(`[citizen-agent-manager] Added agent ${agentId} to openclaw.json`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function removeAgentFromConfig(agentId: string): void {
|
|
117
|
+
const cfg = loadOpenClawConfig();
|
|
118
|
+
const agents: any[] = cfg.agents?.list ?? [];
|
|
119
|
+
const before = agents.length;
|
|
120
|
+
cfg.agents.list = agents.filter((a: any) => a.id !== agentId);
|
|
121
|
+
if (cfg.agents.list.length < before) {
|
|
122
|
+
saveOpenClawConfig(cfg);
|
|
123
|
+
console.log(`[citizen-agent-manager] Removed agent ${agentId} from openclaw.json`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function isAgentInConfig(agentId: string): boolean {
|
|
128
|
+
try {
|
|
129
|
+
const cfg = loadOpenClawConfig();
|
|
130
|
+
return (cfg.agents?.list ?? []).some((a: any) => a.id === agentId);
|
|
131
|
+
} catch {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function buildAgentId(citizenId: string): string {
|
|
137
|
+
return `citizen-${citizenId.replace(/[^a-zA-Z0-9_-]/g, "-")}`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export async function applyAgentChanges(
|
|
141
|
+
changes: AgentChange[],
|
|
142
|
+
): Promise<AgentChangeResult[]> {
|
|
143
|
+
const results: AgentChangeResult[] = [];
|
|
144
|
+
|
|
145
|
+
for (const change of changes) {
|
|
146
|
+
try {
|
|
147
|
+
switch (change.action) {
|
|
148
|
+
case "create": {
|
|
149
|
+
if (!change.soulContent) throw new Error("soulContent is required for create");
|
|
150
|
+
createAgentWorkspace(change.agentId, change.soulContent, change.citizenName, change.specialty);
|
|
151
|
+
addAgentToConfig(change.agentId, change.citizenName, change.specialty);
|
|
152
|
+
results.push({ citizenId: change.citizenId, action: "create", success: true, agentId: change.agentId });
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
case "disable": {
|
|
156
|
+
removeAgentFromConfig(change.agentId);
|
|
157
|
+
results.push({ citizenId: change.citizenId, action: "disable", success: true, agentId: change.agentId });
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case "update_soul": {
|
|
161
|
+
if (!change.soulContent) throw new Error("soulContent is required for update_soul");
|
|
162
|
+
updateSoulFile(change.agentId, change.soulContent, change.citizenName, change.specialty);
|
|
163
|
+
if (!isAgentInConfig(change.agentId)) {
|
|
164
|
+
addAgentToConfig(change.agentId, change.citizenName);
|
|
165
|
+
}
|
|
166
|
+
results.push({ citizenId: change.citizenId, action: "update_soul", success: true, agentId: change.agentId });
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
} catch (err: any) {
|
|
171
|
+
const errMsg = err?.message ?? "Unknown error";
|
|
172
|
+
console.error(`[citizen-agent-manager] Failed to ${change.action} agent for ${change.citizenName}: ${errMsg}`);
|
|
173
|
+
results.push({ citizenId: change.citizenId, action: change.action, success: false, error: errMsg });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return results;
|
|
178
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Routes user messages to independent citizen agents.
|
|
3
|
+
* Reads agentId from citizen-config.json (published) and dispatches
|
|
4
|
+
* to the citizen's own session via SessionKey = "agent:{agentId}:{townSessionId}".
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { getTownRuntime } from "./runtime.js";
|
|
8
|
+
import { pushCitizenMessages } from "./ws-server.js";
|
|
9
|
+
import { sanitizeTownSessionId } from "./town-session.js";
|
|
10
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
|
|
14
|
+
const CHANNEL_ID = "agentshire";
|
|
15
|
+
|
|
16
|
+
function getPublishedConfigPath(): string {
|
|
17
|
+
const pluginDir = join(fileURLToPath(import.meta.url), "..", "..", "..");
|
|
18
|
+
return join(pluginDir, "town-data", "citizen-config.json");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function findCitizenAgentId(npcId: string): string | null {
|
|
22
|
+
try {
|
|
23
|
+
const configPath = getPublishedConfigPath();
|
|
24
|
+
if (!existsSync(configPath)) return null;
|
|
25
|
+
const config = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
26
|
+
const characters: any[] = config.characters ?? [];
|
|
27
|
+
const citizen = characters.find((c: any) => c.id === npcId && c.role === "citizen");
|
|
28
|
+
if (!citizen?.agentEnabled || !citizen?.agentId) return null;
|
|
29
|
+
return citizen.agentId;
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function routeCitizenMessage(params: {
|
|
36
|
+
npcId: string;
|
|
37
|
+
label: string;
|
|
38
|
+
message: string;
|
|
39
|
+
townSessionId: string;
|
|
40
|
+
accountId: string;
|
|
41
|
+
cfg: Record<string, unknown>;
|
|
42
|
+
mediaPaths?: string[];
|
|
43
|
+
}): Promise<void> {
|
|
44
|
+
const { npcId, label, message, townSessionId, accountId, cfg, mediaPaths } = params;
|
|
45
|
+
|
|
46
|
+
const agentId = findCitizenAgentId(npcId);
|
|
47
|
+
if (!agentId) {
|
|
48
|
+
console.log(`[citizen-chat] No active agent for ${label} (${npcId}), message dropped`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const rt = getTownRuntime();
|
|
53
|
+
const sanitizedSession = sanitizeTownSessionId(townSessionId);
|
|
54
|
+
const sessionKey = `agent:${agentId}:${sanitizedSession}`;
|
|
55
|
+
|
|
56
|
+
console.log(`[citizen-chat] Routing to ${agentId} (${label}), sessionKey=${sessionKey}`);
|
|
57
|
+
|
|
58
|
+
const msgCtx = rt.channel.reply.finalizeInboundContext({
|
|
59
|
+
Body: message,
|
|
60
|
+
RawBody: message,
|
|
61
|
+
CommandBody: message,
|
|
62
|
+
From: `${CHANNEL_ID}:user`,
|
|
63
|
+
To: `${CHANNEL_ID}:${npcId}`,
|
|
64
|
+
SessionKey: sessionKey,
|
|
65
|
+
AccountId: accountId,
|
|
66
|
+
OriginatingChannel: CHANNEL_ID,
|
|
67
|
+
ChatType: "direct",
|
|
68
|
+
SenderId: "user",
|
|
69
|
+
Provider: CHANNEL_ID,
|
|
70
|
+
Surface: CHANNEL_ID,
|
|
71
|
+
...(mediaPaths?.length ? { MediaPaths: mediaPaths } : {}),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
await rt.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
|
|
75
|
+
ctx: msgCtx,
|
|
76
|
+
cfg,
|
|
77
|
+
dispatcherOptions: {
|
|
78
|
+
deliver: async (_payload: any) => {
|
|
79
|
+
setTimeout(() => pushCitizenMessages(agentId, townSessionId), 500);
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
export interface WorkshopUserConfig {
|
|
5
|
+
name: string;
|
|
6
|
+
avatarUrl?: string;
|
|
7
|
+
avatarId: string;
|
|
8
|
+
modelSource: "builtin" | "library" | "custom";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface WorkshopStewardConfig {
|
|
12
|
+
name: string;
|
|
13
|
+
avatarUrl?: string;
|
|
14
|
+
avatarId: string;
|
|
15
|
+
modelSource: "builtin" | "library" | "custom";
|
|
16
|
+
bio: string;
|
|
17
|
+
persona: string;
|
|
18
|
+
boundAgentId?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface WorkshopCitizenConfig {
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
avatarUrl?: string;
|
|
25
|
+
avatarId: string;
|
|
26
|
+
modelSource: "builtin" | "library" | "custom";
|
|
27
|
+
bio: string;
|
|
28
|
+
industry: string;
|
|
29
|
+
specialty: string;
|
|
30
|
+
persona: string;
|
|
31
|
+
homeId: string;
|
|
32
|
+
boundAgentId?: string;
|
|
33
|
+
boundSubAgentId?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface CitizenWorkshopConfig {
|
|
37
|
+
version: 1;
|
|
38
|
+
user: WorkshopUserConfig;
|
|
39
|
+
steward: WorkshopStewardConfig;
|
|
40
|
+
citizens: WorkshopCitizenConfig[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class CitizenWorkshopManager {
|
|
44
|
+
private configPath: string;
|
|
45
|
+
private soulsDir: string;
|
|
46
|
+
|
|
47
|
+
constructor(pluginDir: string) {
|
|
48
|
+
const townDataDir = join(pluginDir, "town-data");
|
|
49
|
+
this.configPath = join(townDataDir, "citizen-config.json");
|
|
50
|
+
this.soulsDir = join(townDataDir, "souls");
|
|
51
|
+
this.ensureDirs();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private ensureDirs(): void {
|
|
55
|
+
if (!existsSync(this.soulsDir)) mkdirSync(this.soulsDir, { recursive: true });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
loadConfig(): CitizenWorkshopConfig | null {
|
|
59
|
+
if (!existsSync(this.configPath)) return null;
|
|
60
|
+
try {
|
|
61
|
+
return JSON.parse(readFileSync(this.configPath, "utf-8"));
|
|
62
|
+
} catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
saveConfig(config: CitizenWorkshopConfig): void {
|
|
68
|
+
writeFileSync(this.configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
saveSoul(name: string, content: string): void {
|
|
72
|
+
const fileName = `${name.toUpperCase()}.md`;
|
|
73
|
+
writeFileSync(join(this.soulsDir, fileName), content, "utf-8");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
loadSoul(name: string): string | null {
|
|
77
|
+
const fileName = `${name.toUpperCase()}.md`;
|
|
78
|
+
const filePath = join(this.soulsDir, fileName);
|
|
79
|
+
if (!existsSync(filePath)) return null;
|
|
80
|
+
try {
|
|
81
|
+
return readFileSync(filePath, "utf-8");
|
|
82
|
+
} catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
listSouls(): string[] {
|
|
88
|
+
try {
|
|
89
|
+
return readdirSync(this.soulsDir)
|
|
90
|
+
.filter((f: string) => f.endsWith(".md"))
|
|
91
|
+
.map((f: string) => f.replace(/\.md$/i, ""));
|
|
92
|
+
} catch {
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, unlinkSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
|
|
5
|
+
export type CustomAssetKind = "model" | "character";
|
|
6
|
+
|
|
7
|
+
export interface CharacterAnimationSet {
|
|
8
|
+
idle: boolean;
|
|
9
|
+
walk: boolean;
|
|
10
|
+
work: boolean;
|
|
11
|
+
wave: boolean;
|
|
12
|
+
cheer: boolean;
|
|
13
|
+
dance: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface CustomAsset {
|
|
17
|
+
id: string;
|
|
18
|
+
kind: CustomAssetKind;
|
|
19
|
+
name: string;
|
|
20
|
+
fileName: string;
|
|
21
|
+
fileSize: number;
|
|
22
|
+
createdAt: string;
|
|
23
|
+
updatedAt: string;
|
|
24
|
+
cells?: [number, number];
|
|
25
|
+
scale?: number;
|
|
26
|
+
assetType?: string;
|
|
27
|
+
fixRotationX?: number;
|
|
28
|
+
fixRotationY?: number;
|
|
29
|
+
fixRotationZ?: number;
|
|
30
|
+
thumbnail?: string;
|
|
31
|
+
thumbnailFileName?: string;
|
|
32
|
+
animFileName?: string;
|
|
33
|
+
detectedAnimations?: CharacterAnimationSet;
|
|
34
|
+
gender?: "male" | "female" | "neutral";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface CustomAssetCatalog {
|
|
38
|
+
version: 1;
|
|
39
|
+
assets: CustomAsset[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const MAX_FILE_SIZE = 30 * 1024 * 1024; // 30MB
|
|
43
|
+
const MAX_ASSET_COUNT = 20;
|
|
44
|
+
const ALLOWED_EXT = ".glb";
|
|
45
|
+
|
|
46
|
+
export class CustomAssetManager {
|
|
47
|
+
private catalogPath: string;
|
|
48
|
+
private baseDir: string;
|
|
49
|
+
|
|
50
|
+
constructor(pluginDir: string) {
|
|
51
|
+
this.baseDir = join(pluginDir, "town-data", "custom-assets");
|
|
52
|
+
this.catalogPath = join(this.baseDir, "_catalog.json");
|
|
53
|
+
this.ensureDirs();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private ensureDirs(): void {
|
|
57
|
+
for (const sub of ["models", "characters", "thumbnails"]) {
|
|
58
|
+
const dir = join(this.baseDir, sub);
|
|
59
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
60
|
+
}
|
|
61
|
+
if (!existsSync(this.catalogPath)) {
|
|
62
|
+
this.writeCatalog({ version: 1, assets: [] });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private saveThumbnailFile(assetId: string, dataUrl: string): string | null {
|
|
67
|
+
try {
|
|
68
|
+
const match = dataUrl.match(/^data:image\/(\w+);base64,(.+)$/);
|
|
69
|
+
if (!match) return null;
|
|
70
|
+
const ext = match[1] === "jpeg" ? "jpg" : match[1];
|
|
71
|
+
const outName = `${assetId}.${ext}`;
|
|
72
|
+
writeFileSync(join(this.baseDir, "thumbnails", outName), Buffer.from(match[2], "base64"));
|
|
73
|
+
return outName;
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private deleteThumbnailFile(fileName?: string): void {
|
|
80
|
+
if (!fileName) return;
|
|
81
|
+
try {
|
|
82
|
+
const fp = join(this.baseDir, "thumbnails", fileName);
|
|
83
|
+
if (existsSync(fp)) unlinkSync(fp);
|
|
84
|
+
} catch { /* already gone */ }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
getThumbnailUrl(asset: CustomAsset): string | undefined {
|
|
88
|
+
if (asset.thumbnailFileName) return `/custom-assets/thumbnails/${asset.thumbnailFileName}`;
|
|
89
|
+
if (asset.thumbnail && !asset.thumbnail.startsWith("data:")) return asset.thumbnail;
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
migrateThumbnails(): boolean {
|
|
94
|
+
const catalog = this.readCatalog();
|
|
95
|
+
let changed = false;
|
|
96
|
+
for (const asset of catalog.assets) {
|
|
97
|
+
if (asset.thumbnailFileName) continue;
|
|
98
|
+
if (!asset.thumbnail || !asset.thumbnail.startsWith("data:")) continue;
|
|
99
|
+
const outName = this.saveThumbnailFile(asset.id, asset.thumbnail);
|
|
100
|
+
if (outName) {
|
|
101
|
+
asset.thumbnailFileName = outName;
|
|
102
|
+
delete asset.thumbnail;
|
|
103
|
+
changed = true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (changed) this.writeCatalog(catalog);
|
|
107
|
+
return changed;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private readCatalog(): CustomAssetCatalog {
|
|
111
|
+
try {
|
|
112
|
+
return JSON.parse(readFileSync(this.catalogPath, "utf-8"));
|
|
113
|
+
} catch {
|
|
114
|
+
return { version: 1, assets: [] };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private writeCatalog(catalog: CustomAssetCatalog): void {
|
|
119
|
+
writeFileSync(this.catalogPath, JSON.stringify(catalog, null, 2), "utf-8");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
listAssets(kind?: CustomAssetKind): CustomAsset[] {
|
|
123
|
+
const catalog = this.readCatalog();
|
|
124
|
+
if (kind) return catalog.assets.filter((a) => a.kind === kind);
|
|
125
|
+
return catalog.assets;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
saveAsset(params: {
|
|
129
|
+
kind: CustomAssetKind;
|
|
130
|
+
name: string;
|
|
131
|
+
data: string; // base64
|
|
132
|
+
cells?: [number, number];
|
|
133
|
+
scale?: number;
|
|
134
|
+
assetType?: string;
|
|
135
|
+
fixRotationX?: number;
|
|
136
|
+
fixRotationY?: number;
|
|
137
|
+
fixRotationZ?: number;
|
|
138
|
+
thumbnail?: string;
|
|
139
|
+
}): CustomAsset | { error: string } {
|
|
140
|
+
const catalog = this.readCatalog();
|
|
141
|
+
|
|
142
|
+
if (catalog.assets.length >= MAX_ASSET_COUNT) {
|
|
143
|
+
return { error: `最多添加 ${MAX_ASSET_COUNT} 个自定义资产` };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const buf = Buffer.from(params.data, "base64");
|
|
147
|
+
if (buf.length > MAX_FILE_SIZE) {
|
|
148
|
+
return { error: "文件超过 30MB 限制" };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const id = randomUUID();
|
|
152
|
+
const fileName = `${id}${ALLOWED_EXT}`;
|
|
153
|
+
const subDir = params.kind === "character" ? "characters" : "models";
|
|
154
|
+
const filePath = join(this.baseDir, subDir, fileName);
|
|
155
|
+
|
|
156
|
+
writeFileSync(filePath, buf);
|
|
157
|
+
|
|
158
|
+
const now = new Date().toISOString();
|
|
159
|
+
let thumbnailFileName: string | undefined;
|
|
160
|
+
if (params.thumbnail && params.thumbnail.startsWith("data:")) {
|
|
161
|
+
const outName = this.saveThumbnailFile(id, params.thumbnail);
|
|
162
|
+
if (outName) thumbnailFileName = outName;
|
|
163
|
+
}
|
|
164
|
+
const asset: CustomAsset = {
|
|
165
|
+
id,
|
|
166
|
+
kind: params.kind,
|
|
167
|
+
name: params.name.slice(0, 20),
|
|
168
|
+
fileName,
|
|
169
|
+
fileSize: buf.length,
|
|
170
|
+
createdAt: now,
|
|
171
|
+
updatedAt: now,
|
|
172
|
+
cells: params.cells,
|
|
173
|
+
scale: params.scale,
|
|
174
|
+
assetType: params.assetType,
|
|
175
|
+
fixRotationX: params.fixRotationX,
|
|
176
|
+
fixRotationY: params.fixRotationY,
|
|
177
|
+
fixRotationZ: params.fixRotationZ,
|
|
178
|
+
...(thumbnailFileName
|
|
179
|
+
? { thumbnailFileName }
|
|
180
|
+
: params.thumbnail ? { thumbnail: params.thumbnail } : {}),
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
catalog.assets.unshift(asset);
|
|
184
|
+
this.writeCatalog(catalog);
|
|
185
|
+
return asset;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
updateAsset(
|
|
189
|
+
id: string,
|
|
190
|
+
updates: Partial<Pick<CustomAsset, "name" | "cells" | "scale" | "assetType" | "fixRotationX" | "fixRotationY" | "fixRotationZ" | "thumbnail">>,
|
|
191
|
+
): CustomAsset | { error: string } {
|
|
192
|
+
const catalog = this.readCatalog();
|
|
193
|
+
const asset = catalog.assets.find((a) => a.id === id);
|
|
194
|
+
if (!asset) return { error: "资产不存在" };
|
|
195
|
+
|
|
196
|
+
if (updates.name !== undefined) asset.name = updates.name.slice(0, 20);
|
|
197
|
+
if (updates.cells !== undefined) asset.cells = updates.cells;
|
|
198
|
+
if (updates.scale !== undefined) asset.scale = updates.scale;
|
|
199
|
+
if (updates.assetType !== undefined) asset.assetType = updates.assetType;
|
|
200
|
+
if (updates.fixRotationX !== undefined) asset.fixRotationX = updates.fixRotationX;
|
|
201
|
+
if (updates.fixRotationY !== undefined) asset.fixRotationY = updates.fixRotationY;
|
|
202
|
+
if (updates.fixRotationZ !== undefined) asset.fixRotationZ = updates.fixRotationZ;
|
|
203
|
+
if (updates.thumbnail !== undefined) {
|
|
204
|
+
if (updates.thumbnail && updates.thumbnail.startsWith("data:")) {
|
|
205
|
+
const outName = this.saveThumbnailFile(asset.id, updates.thumbnail);
|
|
206
|
+
if (outName) {
|
|
207
|
+
this.deleteThumbnailFile(asset.thumbnailFileName);
|
|
208
|
+
asset.thumbnailFileName = outName;
|
|
209
|
+
delete asset.thumbnail;
|
|
210
|
+
} else {
|
|
211
|
+
asset.thumbnail = updates.thumbnail;
|
|
212
|
+
}
|
|
213
|
+
} else {
|
|
214
|
+
asset.thumbnail = updates.thumbnail;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
asset.updatedAt = new Date().toISOString();
|
|
218
|
+
|
|
219
|
+
this.writeCatalog(catalog);
|
|
220
|
+
return asset;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
deleteAsset(id: string): { success: boolean; error?: string } {
|
|
224
|
+
const catalog = this.readCatalog();
|
|
225
|
+
const idx = catalog.assets.findIndex((a) => a.id === id);
|
|
226
|
+
if (idx < 0) return { success: false, error: "资产不存在" };
|
|
227
|
+
|
|
228
|
+
const asset = catalog.assets[idx];
|
|
229
|
+
const subDir = asset.kind === "character" ? "characters" : "models";
|
|
230
|
+
const filePath = join(this.baseDir, subDir, asset.fileName);
|
|
231
|
+
|
|
232
|
+
try {
|
|
233
|
+
if (existsSync(filePath)) unlinkSync(filePath);
|
|
234
|
+
} catch {
|
|
235
|
+
/* file already gone */
|
|
236
|
+
}
|
|
237
|
+
this.deleteThumbnailFile(asset.thumbnailFileName);
|
|
238
|
+
|
|
239
|
+
catalog.assets.splice(idx, 1);
|
|
240
|
+
this.writeCatalog(catalog);
|
|
241
|
+
return { success: true };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
getFilePath(kind: CustomAssetKind, fileName: string): string | null {
|
|
245
|
+
const subDir = kind === "character" ? "characters" : "models";
|
|
246
|
+
const filePath = join(this.baseDir, subDir, fileName);
|
|
247
|
+
if (existsSync(filePath) && statSync(filePath).isFile()) return filePath;
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
}
|