@agent-os-lab/agent-game-sdk 0.1.12 → 0.1.13

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-os-lab/agent-game-sdk",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src",
@@ -1,10 +1,27 @@
1
- import {
2
- AgentGameError,
3
- normalizeAgentAvatarAnimationFrames,
4
- validateAgentAvatarDefinition,
5
- type AgentAvatarAnimationName,
6
- type AgentAvatarDefinition,
7
- } from "../core";
1
+ import { AgentGameError } from "../core/errors";
2
+
3
+ const REQUIRED_AGENT_AVATAR_ANIMATIONS = [
4
+ "idle.down",
5
+ "idle.up",
6
+ "idle.left",
7
+ "idle.right",
8
+ "walk.down",
9
+ "walk.up",
10
+ "walk.left",
11
+ "walk.right",
12
+ "work.typing",
13
+ "emote.think",
14
+ "emote.talk",
15
+ ] as const;
16
+
17
+ export type AgentAvatarAnimationName = (typeof REQUIRED_AGENT_AVATAR_ANIMATIONS)[number];
18
+ export type AgentAvatarAnimationFrames = string | string[];
19
+ export type AgentAvatarDefinition = {
20
+ id: string;
21
+ imageUrl: string;
22
+ atlasUrl: string;
23
+ animations: Partial<Record<AgentAvatarAnimationName, AgentAvatarAnimationFrames>> & Record<string, AgentAvatarAnimationFrames>;
24
+ };
8
25
 
9
26
  export type AgentAvatarAtlasFrame = {
10
27
  frame: {
@@ -195,6 +212,37 @@ function resolveAnimationFrameName(
195
212
  return frames[index]!;
196
213
  }
197
214
 
215
+ function validateAgentAvatarDefinition(avatar: AgentAvatarDefinition): AgentAvatarDefinition {
216
+ assertNonEmpty(avatar.id, "avatar id");
217
+ assertNonEmpty(avatar.imageUrl, "avatar image url");
218
+ assertNonEmpty(avatar.atlasUrl, "avatar atlas url");
219
+
220
+ for (const animation of REQUIRED_AGENT_AVATAR_ANIMATIONS) {
221
+ if (!avatar.animations[animation]) {
222
+ throw new AgentGameError("missing_animation", `Agent game avatar ${avatar.id} is missing animation: ${animation}`);
223
+ }
224
+ const frames = normalizeAgentAvatarAnimationFrames(avatar.animations[animation]);
225
+ if (frames.length === 0) {
226
+ throw new AgentGameError("missing_animation", `Agent game avatar ${avatar.id} is missing animation: ${animation}`);
227
+ }
228
+ }
229
+
230
+ return avatar;
231
+ }
232
+
233
+ function normalizeAgentAvatarAnimationFrames(frames: AgentAvatarAnimationFrames | undefined): string[] {
234
+ if (frames === undefined) {
235
+ return [];
236
+ }
237
+ return Array.isArray(frames) ? frames : [frames];
238
+ }
239
+
240
+ function assertNonEmpty(value: string, field: string): void {
241
+ if (!value || value.trim().length === 0) {
242
+ throw new AgentGameError("invalid_asset_manifest", `Agent game ${field} must not be empty`);
243
+ }
244
+ }
245
+
198
246
  function assertPositiveFiniteInteger(value: number, field: string): number {
199
247
  if (!Number.isInteger(value) || value <= 0) {
200
248
  throw new AgentGameError("invalid_asset_manifest", `Agent avatar canvas ${field} must be a positive integer`);
@@ -1,7 +1,7 @@
1
1
  import * as THREE from "three";
2
2
 
3
3
  import type { AgentGameOfficeAgent, AgentGameOfficeSceneState } from "../office/core/types";
4
- import { AgentGameError } from "../core";
4
+ import { AgentGameError } from "../core/errors";
5
5
  import {
6
6
  createAgentAvatar3DScene,
7
7
  type ResolvedAgentAvatar3DState,