@myclaw163/clawclaw-cli 0.8.36 → 0.8.37
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/package.json +1 -1
- package/src/pipeline/event-format.ts +38 -19
package/package.json
CHANGED
|
@@ -101,36 +101,55 @@ function projectCurrentScene(
|
|
|
101
101
|
const seatsByName = new Map(players
|
|
102
102
|
.filter((player) => player.seat !== undefined)
|
|
103
103
|
.map((player) => [player.name, player.seat] as const));
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
104
|
+
const sceneItem = (raw: unknown): Record<string, unknown> | null => (
|
|
105
|
+
raw && typeof raw === 'object' && !Array.isArray(raw) ? raw as Record<string, unknown> : null
|
|
106
|
+
);
|
|
107
|
+
const identity = (item: Record<string, unknown>) => {
|
|
108
|
+
const player: Record<string, unknown> = item.player && typeof item.player === 'object' && !Array.isArray(item.player)
|
|
109
|
+
? item.player as Record<string, unknown>
|
|
109
110
|
: {};
|
|
110
111
|
const name = stringValue(player.name);
|
|
111
112
|
const seat = numberValue(player.seat) ?? (name ? seatsByName.get(name) : undefined);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
113
|
+
return { name, seat };
|
|
114
|
+
};
|
|
115
|
+
const location = (item: Record<string, unknown>) => cleanObject({
|
|
116
|
+
room: stringValue(item.room),
|
|
117
|
+
relative_direction: sceneDirection(item, observer),
|
|
118
|
+
distance_px: sceneDistance(item, observer),
|
|
119
|
+
});
|
|
120
|
+
const projectPlayer = (raw: unknown): Record<string, unknown> | null => {
|
|
121
|
+
const item = sceneItem(raw);
|
|
122
|
+
if (!item) return null;
|
|
123
|
+
const player = identity(item);
|
|
124
|
+
if (!player.name && player.seat === undefined) return null;
|
|
125
|
+
return cleanObject({ ...player, ...location(item) });
|
|
126
|
+
};
|
|
127
|
+
const projectCorpse = (raw: unknown): Record<string, unknown> | null => {
|
|
128
|
+
const item = sceneItem(raw);
|
|
129
|
+
if (!item) return null;
|
|
130
|
+
const player = identity(item);
|
|
131
|
+
const place = location(item);
|
|
132
|
+
// Visibility does not imply identification. Preserve anonymous spatial facts
|
|
133
|
+
// without exposing corpse/player IDs or inventing a name or seat.
|
|
134
|
+
if (!player.name && player.seat === undefined && Object.keys(place).length === 0) return null;
|
|
135
|
+
return cleanObject({ ...player, ...place });
|
|
120
136
|
};
|
|
121
|
-
const projectList = (
|
|
137
|
+
const projectList = (
|
|
138
|
+
raw: unknown,
|
|
139
|
+
project: (item: unknown) => Record<string, unknown> | null,
|
|
140
|
+
): Record<string, unknown>[] | undefined => {
|
|
122
141
|
if (!Array.isArray(raw)) return undefined;
|
|
123
|
-
const projected = raw.map(
|
|
142
|
+
const projected = raw.map(project);
|
|
124
143
|
// An explicit empty set means "nobody visible". A non-empty source with
|
|
125
|
-
// an
|
|
144
|
+
// an unprojectable entry is instead unavailable evidence; do not silently
|
|
126
145
|
// turn a projection failure into an authoritative empty/partial scene.
|
|
127
146
|
return projected.some((item) => item === null)
|
|
128
147
|
? undefined
|
|
129
|
-
: projected as Record<string,
|
|
148
|
+
: projected as Record<string, unknown>[];
|
|
130
149
|
};
|
|
131
150
|
return cleanObject({
|
|
132
|
-
visible_players: projectList(summary.visible_players,
|
|
133
|
-
nearby_corpses: projectList(summary.visible_corpses,
|
|
151
|
+
visible_players: projectList(summary.visible_players, projectPlayer),
|
|
152
|
+
nearby_corpses: projectList(summary.visible_corpses, projectCorpse),
|
|
134
153
|
});
|
|
135
154
|
}
|
|
136
155
|
|