anva-sdk 0.1.0 → 0.2.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.
Files changed (2) hide show
  1. package/index.js +45 -22
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * import { Anva } from "anva";
5
5
  * const client = new Anva(process.env.ANVA_KEY);
6
- * const session = await client.createSession({ characterId: "char_..." });
6
+ * const session = await client.createSession({ presetId: "..." });
7
7
  * // put session.embed_url in an <iframe allow="camera; microphone; autoplay">
8
8
  *
9
9
  * Works in Node 18+ (global fetch/WebSocket) and modern browsers — but keep
@@ -36,43 +36,60 @@ export class Anva {
36
36
  // -- sessions -------------------------------------------------------------
37
37
 
38
38
  /**
39
- * Create a live session. Returns { session_id, session_token, embed_url,
40
- * events_ws_url, expires_at, ... }.
39
+ * Create a live session, one of two ways:
40
+ * - Embed tier: pass `presetId` (a saved preset from the Playground).
41
+ * - Advanced tier: pass `avatarId` + the persona (`systemPrompt`, `voiceId`,
42
+ * `languageCode`) directly — nothing is stored server-side.
43
+ * Returns { session_id, session_token, embed_url, events_ws_url, expires_at,
44
+ * instance_id, preset_id, avatar_id, ... }.
45
+ *
46
+ * @param {{presetId?: string, avatarId?: string, systemPrompt?: string,
47
+ * voiceId?: string, languageCode?: string, llmMode?: string,
48
+ * webhookUrl?: string, webhookSecret?: string}} params
41
49
  */
42
- createSession({ characterId, llmMode, webhookUrl, webhookSecret }) {
43
- const body = { character_id: characterId };
50
+ createSession(params = {}) {
51
+ const { presetId, avatarId, systemPrompt, voiceId, languageCode, llmMode, webhookUrl, webhookSecret } = params;
52
+ if (!presetId && !avatarId) {
53
+ throw new Error("createSession requires either presetId (embed) or avatarId (advanced persona)");
54
+ }
55
+ const body = {};
56
+ if (presetId) body.preset_id = presetId;
57
+ if (avatarId) body.avatar_id = avatarId;
58
+ if (systemPrompt) body.system_prompt = systemPrompt;
59
+ if (voiceId) body.voice_id = voiceId;
60
+ if (languageCode) body.language_code = languageCode;
44
61
  if (llmMode) body.llm_mode = llmMode;
45
62
  if (webhookUrl) body.webhook_url = webhookUrl;
46
63
  if (webhookSecret) body.webhook_secret = webhookSecret;
47
- return this._request("POST", "/api/v1/sessions", body);
64
+ return this._request("POST", "/api/v2/sessions", body);
48
65
  }
49
66
 
50
67
  getSession(sessionId) {
51
- return this._request("GET", `/api/v1/sessions/${enc(sessionId)}`);
68
+ return this._request("GET", `/api/v2/sessions/${enc(sessionId)}`);
52
69
  }
53
70
 
54
71
  endSession(sessionId) {
55
- return this._request("DELETE", `/api/v1/sessions/${enc(sessionId)}`);
72
+ return this._request("DELETE", `/api/v2/sessions/${enc(sessionId)}`);
56
73
  }
57
74
 
58
75
  /** Have the avatar speak `text` to the user. */
59
76
  sendMessage(sessionId, text) {
60
- return this._request("POST", `/api/v1/sessions/${enc(sessionId)}/messages`, { text });
77
+ return this._request("POST", `/api/v2/sessions/${enc(sessionId)}/messages`, { text });
61
78
  }
62
79
 
63
80
  /** Stop the avatar mid-sentence. */
64
81
  interrupt(sessionId) {
65
- return this._request("POST", `/api/v1/sessions/${enc(sessionId)}/interrupt`, {});
82
+ return this._request("POST", `/api/v2/sessions/${enc(sessionId)}/interrupt`, {});
66
83
  }
67
84
 
68
85
  triggerAction(sessionId, name) {
69
- return this._request("POST", `/api/v1/sessions/${enc(sessionId)}/actions`, { name });
86
+ return this._request("POST", `/api/v2/sessions/${enc(sessionId)}/actions`, { name });
70
87
  }
71
88
 
72
89
  /** The authenticated WebSocket URL for the session's event stream. */
73
90
  eventsUrl(sessionId) {
74
91
  const ws = this.baseUrl.replace(/^http/, "ws");
75
- return `${ws}/api/v1/sessions/${enc(sessionId)}/events?api_key=${encodeURIComponent(this.apiKey)}`;
92
+ return `${ws}/api/v2/sessions/${enc(sessionId)}/events?api_key=${encodeURIComponent(this.apiKey)}`;
76
93
  }
77
94
 
78
95
  /**
@@ -124,27 +141,33 @@ export class Anva {
124
141
  }
125
142
  }
126
143
 
127
- // -- characters -----------------------------------------------------------
144
+ // -- presets --------------------------------------------------------------
128
145
 
129
- listCharacters() {
130
- return this._request("GET", "/api/v1/characters");
146
+ listPresets() {
147
+ return this._request("GET", "/api/v2/presets");
131
148
  }
132
149
 
133
- createCharacter({ name, visualCharacterId, systemPrompt, voiceId, languageCode }) {
150
+ createPreset({ name, visualCharacterId, systemPrompt, voiceId, languageCode }) {
134
151
  const body = { name };
135
152
  if (visualCharacterId) body.visual_character_id = visualCharacterId;
136
153
  if (systemPrompt) body.system_prompt = systemPrompt;
137
154
  if (voiceId) body.voice_id = voiceId;
138
155
  if (languageCode) body.language_code = languageCode;
139
- return this._request("POST", "/api/v1/characters", body);
156
+ return this._request("POST", "/api/v2/presets", body);
157
+ }
158
+
159
+ getPreset(presetId) {
160
+ return this._request("GET", `/api/v2/presets/${enc(presetId)}`);
140
161
  }
141
162
 
142
- getCharacter(characterId) {
143
- return this._request("GET", `/api/v1/characters/${enc(characterId)}`);
163
+ deletePreset(presetId) {
164
+ return this._request("DELETE", `/api/v2/presets/${enc(presetId)}`);
144
165
  }
145
166
 
146
- deleteCharacter(characterId) {
147
- return this._request("DELETE", `/api/v1/characters/${enc(characterId)}`);
167
+ // -- instances ------------------------------------------------------------
168
+
169
+ listInstances() {
170
+ return this._request("GET", "/api/v2/instances");
148
171
  }
149
172
 
150
173
  // -- plumbing -------------------------------------------------------------
@@ -155,7 +178,7 @@ export class Anva {
155
178
  headers: {
156
179
  Authorization: `Bearer ${this.apiKey}`,
157
180
  "Content-Type": "application/json",
158
- "User-Agent": "anva-js/0.1.0",
181
+ "User-Agent": "anva-js/0.2.0",
159
182
  },
160
183
  body: body === undefined ? undefined : JSON.stringify(body),
161
184
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anva-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Official JavaScript/TypeScript SDK for Anva \u2014 live AI avatars for your product.",
5
5
  "keywords": [
6
6
  "avatar",