@11labs/client 0.1.3 → 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 (55) hide show
  1. package/README.md +118 -15
  2. package/dist/BaseConversation.d.ts +76 -0
  3. package/dist/TextConversation.d.ts +4 -0
  4. package/dist/VoiceConversation.d.ts +27 -0
  5. package/dist/dist/BaseConversation.d.ts +80 -0
  6. package/dist/dist/TextConversation.d.ts +4 -0
  7. package/dist/dist/VoiceConversation.d.ts +27 -0
  8. package/dist/dist/index.d.ts +12 -0
  9. package/dist/dist/lib.cjs +2 -0
  10. package/dist/dist/lib.cjs.map +1 -0
  11. package/dist/dist/lib.modern.js +2 -0
  12. package/dist/dist/lib.modern.js.map +1 -0
  13. package/dist/dist/lib.module.js +2 -0
  14. package/dist/dist/lib.module.js.map +1 -0
  15. package/dist/dist/lib.umd.js +2 -0
  16. package/dist/dist/lib.umd.js.map +1 -0
  17. package/dist/dist/utils/BaseConnection.d.ts +99 -0
  18. package/dist/dist/utils/ConnectionFactory.d.ts +2 -0
  19. package/dist/dist/utils/WebRTCConnection.d.ts +23 -0
  20. package/dist/dist/utils/WebSocketConnection.d.ts +13 -0
  21. package/dist/dist/utils/applyDelay.d.ts +2 -0
  22. package/dist/dist/utils/audio.d.ts +2 -0
  23. package/dist/dist/utils/audioConcatProcessor.d.ts +1 -0
  24. package/dist/dist/utils/compatibility.d.ts +2 -0
  25. package/dist/dist/utils/createWorkletModuleLoader.d.ts +1 -0
  26. package/dist/dist/utils/events.d.ts +125 -0
  27. package/dist/dist/utils/input.d.ts +14 -0
  28. package/dist/dist/utils/output.d.ts +10 -0
  29. package/dist/dist/utils/overrides.d.ts +4 -0
  30. package/dist/dist/utils/postOverallFeedback.d.ts +1 -0
  31. package/dist/dist/utils/rawAudioProcessor.d.ts +1 -0
  32. package/dist/dist/version.d.ts +1 -0
  33. package/dist/index.d.ts +9 -77
  34. package/dist/lib.cjs +1 -1
  35. package/dist/lib.cjs.map +1 -1
  36. package/dist/lib.modern.js +1 -1
  37. package/dist/lib.modern.js.map +1 -1
  38. package/dist/lib.module.js +1 -1
  39. package/dist/lib.module.js.map +1 -1
  40. package/dist/lib.umd.js +1 -1
  41. package/dist/lib.umd.js.map +1 -1
  42. package/dist/utils/BaseConnection.d.ts +94 -0
  43. package/dist/utils/ConnectionFactory.d.ts +2 -0
  44. package/dist/utils/WebRTCConnection.d.ts +19 -0
  45. package/dist/utils/WebSocketConnection.d.ts +12 -0
  46. package/dist/utils/applyDelay.d.ts +2 -0
  47. package/dist/utils/events.d.ts +20 -3
  48. package/dist/utils/input.d.ts +1 -1
  49. package/dist/utils/output.d.ts +1 -1
  50. package/dist/utils/overrides.d.ts +4 -0
  51. package/dist/utils/postOverallFeedback.d.ts +1 -0
  52. package/dist/version.d.ts +1 -0
  53. package/package.json +17 -12
  54. package/LICENSE +0 -21
  55. package/dist/utils/connection.d.ts +0 -65
@@ -0,0 +1,2 @@
1
+ import type { BaseConnection, SessionConfig } from "./BaseConnection";
2
+ export declare function createConnection(config: SessionConfig): Promise<BaseConnection>;
@@ -0,0 +1,19 @@
1
+ import { BaseConnection, type SessionConfig, type FormatConfig } from "./BaseConnection";
2
+ import { type OutgoingSocketEvent } from "./events";
3
+ import { Room } from "livekit-client";
4
+ export type ConnectionConfig = SessionConfig & {
5
+ onDebug?: (info: unknown) => void;
6
+ };
7
+ export declare class WebRTCConnection extends BaseConnection {
8
+ conversationId: string;
9
+ readonly inputFormat: FormatConfig;
10
+ readonly outputFormat: FormatConfig;
11
+ private room;
12
+ private isConnected;
13
+ private constructor();
14
+ static create(config: ConnectionConfig): Promise<WebRTCConnection>;
15
+ private setupRoomEventListeners;
16
+ close(): void;
17
+ sendMessage(message: OutgoingSocketEvent): Promise<void>;
18
+ getRoom(): Room;
19
+ }
@@ -0,0 +1,12 @@
1
+ import { BaseConnection, type SessionConfig, type FormatConfig } from "./BaseConnection";
2
+ import { type OutgoingSocketEvent } from "./events";
3
+ export declare class WebSocketConnection extends BaseConnection {
4
+ private readonly socket;
5
+ readonly conversationId: string;
6
+ readonly inputFormat: FormatConfig;
7
+ readonly outputFormat: FormatConfig;
8
+ private constructor();
9
+ static create(config: SessionConfig): Promise<WebSocketConnection>;
10
+ close(): void;
11
+ sendMessage(message: OutgoingSocketEvent): void;
12
+ }
@@ -0,0 +1,2 @@
1
+ import type { DelayConfig } from "./connection";
2
+ export declare function applyDelay(delayConfig?: DelayConfig): Promise<void>;
@@ -1,4 +1,5 @@
1
- import { Language } from "./connection";
1
+ import type { Language } from "./connection";
2
+ import type { CONVERSATION_INITIATION_CLIENT_DATA_TYPE } from "./overrides";
2
3
  export type UserTranscriptionEvent = {
3
4
  type: "user_transcript";
4
5
  user_transcription_event: {
@@ -74,7 +75,7 @@ export type ClientToolResultEvent = {
74
75
  is_error: boolean;
75
76
  };
76
77
  export type InitiationClientDataEvent = {
77
- type: "conversation_initiation_client_data";
78
+ type: typeof CONVERSATION_INITIATION_CLIENT_DATA_TYPE;
78
79
  conversation_config_override?: {
79
80
  agent?: {
80
81
  prompt?: {
@@ -86,13 +87,29 @@ export type InitiationClientDataEvent = {
86
87
  tts?: {
87
88
  voice_id?: string;
88
89
  };
90
+ conversation?: {
91
+ text_only?: boolean;
92
+ };
89
93
  };
90
94
  custom_llm_extra_body?: any;
91
95
  dynamic_variables?: Record<string, string | number | boolean>;
96
+ user_id?: string;
92
97
  };
93
98
  export type ContextualUpdateEvent = {
94
99
  type: "contextual_update";
95
100
  text: string;
96
101
  };
97
- export type OutgoingSocketEvent = PongEvent | UserAudioEvent | InitiationClientDataEvent | UserFeedbackEvent | ClientToolResultEvent | ContextualUpdateEvent;
102
+ export type UserMessageEvent = {
103
+ type: "user_message";
104
+ text: string;
105
+ };
106
+ export type UserActivityEvent = {
107
+ type: "user_activity";
108
+ };
109
+ export type MCPToolApprovalResultEvent = {
110
+ type: "mcp_tool_approval_result";
111
+ tool_call_id: string;
112
+ is_approved: boolean;
113
+ };
114
+ export type OutgoingSocketEvent = PongEvent | UserAudioEvent | InitiationClientDataEvent | UserFeedbackEvent | ClientToolResultEvent | ContextualUpdateEvent | UserMessageEvent | UserActivityEvent | MCPToolApprovalResultEvent;
98
115
  export declare function isValidSocketEvent(event: any): event is IncomingSocketEvent;
@@ -1,4 +1,4 @@
1
- import { FormatConfig } from "./connection";
1
+ import type { FormatConfig } from "./connection";
2
2
  export type InputConfig = {
3
3
  preferHeadphonesForIosDevices?: boolean;
4
4
  };
@@ -1,4 +1,4 @@
1
- import { FormatConfig } from "./connection";
1
+ import type { FormatConfig } from "./connection";
2
2
  export declare class Output {
3
3
  readonly context: AudioContext;
4
4
  readonly analyser: AnalyserNode;
@@ -0,0 +1,4 @@
1
+ import type { SessionConfig } from "./BaseConnection";
2
+ import type { InitiationClientDataEvent } from "./events";
3
+ export declare const CONVERSATION_INITIATION_CLIENT_DATA_TYPE = "conversation_initiation_client_data";
4
+ export declare function constructOverrides(config: SessionConfig): InitiationClientDataEvent;
@@ -0,0 +1 @@
1
+ export declare function postOverallFeedback(conversationId: string, like: boolean, origin?: string): Promise<Response>;
@@ -0,0 +1 @@
1
+ export declare const PACKAGE_VERSION = "0.4.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@11labs/client",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "ElevenLabs JavaScript Client Library",
5
5
  "main": "./dist/lib.umd.js",
6
6
  "module": "./dist/lib.module.js",
@@ -15,6 +15,18 @@
15
15
  "require": "./dist/lib.cjs"
16
16
  }
17
17
  },
18
+ "scripts": {
19
+ "generate-version": "printf \"// This file is auto-generated during build\\nexport const PACKAGE_VERSION = \\\"%s\\\";\\n\" \"$npm_package_version\" > src/version.ts",
20
+ "prebuild": "npm run generate-version",
21
+ "build": "BROWSERSLIST_ENV=modern microbundle --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react src/index.ts",
22
+ "clean": "rm -rf ./dist",
23
+ "dev": "npm run clean && npm run generate-version && BROWSERSLIST_ENV=development microbundle --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react src/index.ts -w -f modern",
24
+ "lint": "npm run lint:ts && npm run lint:es && npm run lint:prettier",
25
+ "lint:ts": "tsc --noEmit --skipLibCheck",
26
+ "lint:es": "npx eslint .",
27
+ "lint:prettier": "prettier 'src/**/*.ts' --check",
28
+ "test": "vitest"
29
+ },
18
30
  "keywords": [],
19
31
  "author": "ElevenLabs",
20
32
  "license": "MIT",
@@ -25,7 +37,7 @@
25
37
  "microbundle": "^0.15.1",
26
38
  "mock-socket": "^9.3.1",
27
39
  "node-wav": "^0.0.2",
28
- "playwright": "^1.46.1",
40
+ "playwright": "^1.54.1",
29
41
  "typescript": "^5.5.4",
30
42
  "vitest": "^3.0.5"
31
43
  },
@@ -34,14 +46,7 @@
34
46
  "url": "git+https://github.com/elevenlabs/packages.git",
35
47
  "directory": "packages/client"
36
48
  },
37
- "scripts": {
38
- "build": "BROWSERSLIST_ENV=modern microbundle --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react src/index.ts",
39
- "clean": "rm -rf ./dist",
40
- "dev": "npm run clean && BROWSERSLIST_ENV=development microbundle --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react src/index.ts -w -f modern",
41
- "lint": "npm run lint:ts && npm run lint:es && npm run lint:prettier",
42
- "lint:ts": "tsc --noEmit --skipLibCheck",
43
- "lint:es": "npx eslint .",
44
- "lint:prettier": "prettier 'src/**/*.ts' --check",
45
- "test": "vitest"
49
+ "dependencies": {
50
+ "livekit-client": "^2.11.4"
46
51
  }
47
- }
52
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 ElevenLabs
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,65 +0,0 @@
1
- import { OutgoingSocketEvent, IncomingSocketEvent } from "./events";
2
- export type Language = "en" | "ja" | "zh" | "de" | "hi" | "fr" | "ko" | "pt" | "pt-br" | "it" | "es" | "id" | "nl" | "tr" | "pl" | "sv" | "bg" | "ro" | "ar" | "cs" | "el" | "fi" | "ms" | "da" | "ta" | "uk" | "ru" | "hu" | "no" | "vi";
3
- export type SessionConfig = {
4
- origin?: string;
5
- authorization?: string;
6
- overrides?: {
7
- agent?: {
8
- prompt?: {
9
- prompt?: string;
10
- };
11
- firstMessage?: string;
12
- language?: Language;
13
- };
14
- tts?: {
15
- voiceId?: string;
16
- };
17
- };
18
- customLlmExtraBody?: any;
19
- dynamicVariables?: Record<string, string | number | boolean>;
20
- useWakeLock?: boolean;
21
- connectionDelay?: {
22
- default: number;
23
- android?: number;
24
- ios?: number;
25
- };
26
- } & ({
27
- signedUrl: string;
28
- agentId?: undefined;
29
- } | {
30
- agentId: string;
31
- signedUrl?: undefined;
32
- });
33
- export type FormatConfig = {
34
- format: "pcm" | "ulaw";
35
- sampleRate: number;
36
- };
37
- export type DisconnectionDetails = {
38
- reason: "error";
39
- message: string;
40
- context: Event;
41
- } | {
42
- reason: "agent";
43
- context: CloseEvent;
44
- } | {
45
- reason: "user";
46
- };
47
- export type OnDisconnectCallback = (details: DisconnectionDetails) => void;
48
- export type OnMessageCallback = (event: IncomingSocketEvent) => void;
49
- export declare class Connection {
50
- readonly socket: WebSocket;
51
- readonly conversationId: string;
52
- readonly inputFormat: FormatConfig;
53
- readonly outputFormat: FormatConfig;
54
- static create(config: SessionConfig): Promise<Connection>;
55
- private queue;
56
- private disconnectionDetails;
57
- private onDisconnectCallback;
58
- private onMessageCallback;
59
- private constructor();
60
- close(): void;
61
- sendMessage(message: OutgoingSocketEvent): void;
62
- onMessage(callback: OnMessageCallback): void;
63
- onDisconnect(callback: OnDisconnectCallback): void;
64
- private disconnect;
65
- }