@convai/embody 0.1.0 → 0.2.1

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.
@@ -21,15 +21,45 @@
21
21
  * than trusted.
22
22
  */
23
23
  export const DEFAULT_BASE_URL = 'https://api-stg.convai.com';
24
+ /** Shared so `createCharacter` and the resolver cannot drift apart. */
25
+ export const MISSING_CREDENTIAL = '@convai/embody: a credential is required — pass `token` (recommended for ' +
26
+ 'browsers) or `apiKey`. There is no anonymous access to Convai.';
24
27
  export function httpResolver(opts = {}) {
25
28
  const baseUrl = opts.baseUrl ?? DEFAULT_BASE_URL;
26
29
  return {
27
30
  async resolve(characterId) {
31
+ // Header names are NOT a choice — they are what the backend reads.
32
+ // middleman looks at exactly "API-AUTH-TOKEN" and "CONVAI-API-KEY";
33
+ // an Authorization: Bearer header is ignored. Precedence (token over
34
+ // key) mirrors the SDK's /connect and middleman's own order.
35
+ //
36
+ // A request with neither is refused here rather than sent: there is no
37
+ // anonymous access to Convai, so an unauthenticated request cannot
38
+ // succeed — it would fail later, further from the cause.
39
+ const headers = {};
40
+ if (opts.authToken)
41
+ headers['API-AUTH-TOKEN'] = opts.authToken;
42
+ else if (opts.apiKey)
43
+ headers['CONVAI-API-KEY'] = opts.apiKey;
44
+ else
45
+ throw new Error(MISSING_CREDENTIAL);
28
46
  const res = await fetch(`${baseUrl}/character/${characterId}/embodiment`, {
29
- headers: opts.apiKey ? { 'CONVAI-API-KEY': opts.apiKey } : undefined,
47
+ headers,
30
48
  });
31
- if (!res.ok)
32
- throw new Error(`embodiment resolve failed: HTTP ${res.status}`);
49
+ if (!res.ok) {
50
+ // The body carries the actionable half — "Character has no 3D
51
+ // embodiment configured" reads very differently from a 401, and a
52
+ // bare status code sends people to the wrong problem.
53
+ const detail = await res.text().then((t) => {
54
+ try {
55
+ return JSON.parse(t).ERROR ?? t.slice(0, 200);
56
+ }
57
+ catch {
58
+ return t.slice(0, 200);
59
+ }
60
+ }, () => '');
61
+ throw new Error(`embodiment resolve failed for ${characterId}: HTTP ${res.status}${detail ? ` — ${detail}` : ''}`);
62
+ }
33
63
  return (await res.json());
34
64
  },
35
65
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@convai/embody",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Give a Convai character a body: resolve 3D characters by characterId and drive them with lipsync and animation. Layered on @convai/web-sdk.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Convai <support@convai.com>",
@@ -33,11 +33,13 @@
33
33
  "exports": {
34
34
  ".": {
35
35
  "types": "./dist/index.d.ts",
36
- "import": "./dist/index.js"
36
+ "import": "./dist/index.js",
37
+ "default": "./dist/index.js"
37
38
  },
38
39
  "./react": {
39
40
  "types": "./dist/react/index.d.ts",
40
- "import": "./dist/react/index.js"
41
+ "import": "./dist/react/index.js",
42
+ "default": "./dist/react/index.js"
41
43
  },
42
44
  "./package.json": "./package.json"
43
45
  },
@@ -74,6 +76,7 @@
74
76
  "@convai/web-sdk": "1.8.0-beta.4",
75
77
  "@react-three/fiber": "^8.18.0",
76
78
  "@types/react": "^18.3.31",
79
+ "@types/react-dom": "^19.2.7",
77
80
  "@types/react-test-renderer": "18.3.1",
78
81
  "@types/three": "^0.182.0",
79
82
  "react": "^18.3.1",
@@ -95,12 +98,13 @@
95
98
  "typecheck": "tsc --noEmit",
96
99
  "test": "vitest run",
97
100
  "test:watch": "vitest",
98
- "verify": "pnpm check:hosts && pnpm typecheck && pnpm test && pnpm build",
101
+ "verify": "pnpm check:hosts && pnpm check:tests && pnpm typecheck && pnpm test && pnpm build",
99
102
  "changeset": "changeset",
100
103
  "version": "changeset version",
101
104
  "release": "pnpm build:prod && changeset publish",
102
105
  "release:beta": "pnpm build:beta && changeset publish --tag beta",
103
106
  "check:hosts": "node scripts/check-hosts.mjs",
107
+ "check:tests": "node scripts/check-tests.mjs",
104
108
  "build:stg": "pnpm clean && BRANCH=stg node scripts/check-hosts.mjs && pnpm build",
105
109
  "release:stg": "pnpm build:stg && changeset publish --tag stg",
106
110
  "docs": "typedoc",