@voice-ai-labs/web-sdk 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.
- package/LICENSE +21 -0
- package/README.md +219 -0
- package/dist/__tests__/setup.d.ts +2 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +13 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/client/agents.d.ts +202 -0
- package/dist/client/agents.d.ts.map +1 -0
- package/dist/client/agents.js +233 -0
- package/dist/client/agents.js.map +1 -0
- package/dist/client/analytics.d.ts +77 -0
- package/dist/client/analytics.d.ts.map +1 -0
- package/dist/client/analytics.js +95 -0
- package/dist/client/analytics.js.map +1 -0
- package/dist/client/base.d.ts +69 -0
- package/dist/client/base.d.ts.map +1 -0
- package/dist/client/base.js +210 -0
- package/dist/client/base.js.map +1 -0
- package/dist/client/index.d.ts +71 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +73 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/knowledge-base.d.ts +110 -0
- package/dist/client/knowledge-base.d.ts.map +1 -0
- package/dist/client/knowledge-base.js +126 -0
- package/dist/client/knowledge-base.js.map +1 -0
- package/dist/client/phone-numbers.d.ts +116 -0
- package/dist/client/phone-numbers.d.ts.map +1 -0
- package/dist/client/phone-numbers.js +143 -0
- package/dist/client/phone-numbers.js.map +1 -0
- package/dist/components/VoiceAgentWidget.d.ts +80 -0
- package/dist/components/VoiceAgentWidget.d.ts.map +1 -0
- package/dist/components/VoiceAgentWidget.js +407 -0
- package/dist/components/VoiceAgentWidget.js.map +1 -0
- package/dist/components/index.d.ts +14 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +13 -0
- package/dist/components/index.js.map +1 -0
- package/dist/index.d.ts +184 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +28724 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +28732 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +453 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Voice.ai
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# Voice.AI Web SDK
|
|
2
|
+
|
|
3
|
+
The official Voice.AI SDK for JavaScript/TypeScript applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @voice-ai-labs/web-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import VoiceAI from '@voice-ai-labs/web-sdk';
|
|
15
|
+
|
|
16
|
+
// Initialize with your API key
|
|
17
|
+
const voiceai = new VoiceAI({ apiKey: 'vk_your_api_key' });
|
|
18
|
+
|
|
19
|
+
// Connect to a voice agent
|
|
20
|
+
await voiceai.connect({ agentId: 'your-agent-id' });
|
|
21
|
+
|
|
22
|
+
// Listen for transcriptions
|
|
23
|
+
voiceai.onTranscription((segment) => {
|
|
24
|
+
console.log(`${segment.role}: ${segment.text}`);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Disconnect when done
|
|
28
|
+
await voiceai.disconnect();
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
The SDK provides a unified interface for:
|
|
34
|
+
|
|
35
|
+
- **Real-time Voice** - Connect to voice agents with live transcription
|
|
36
|
+
- **Agent Management** - Create, update, deploy, and manage agents
|
|
37
|
+
- **Analytics** - Access call history and transcripts
|
|
38
|
+
- **Knowledge Base** - Manage RAG documents for your agents
|
|
39
|
+
- **Phone Numbers** - Search and manage phone numbers
|
|
40
|
+
|
|
41
|
+
## Real-time Voice
|
|
42
|
+
|
|
43
|
+
### Connect to an Agent
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
await voiceai.connect({
|
|
47
|
+
agentId: 'agent-123',
|
|
48
|
+
autoPublishMic: true // default: true
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Events
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
// Transcriptions (user and agent speech)
|
|
56
|
+
voiceai.onTranscription((segment) => {
|
|
57
|
+
console.log(`${segment.role}: ${segment.text}`);
|
|
58
|
+
console.log('Final:', segment.isFinal);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Connection status
|
|
62
|
+
voiceai.onStatusChange((status) => {
|
|
63
|
+
if (status.connected) console.log('Connected!');
|
|
64
|
+
if (status.error) console.error('Error:', status.error);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Agent state (listening, speaking, thinking)
|
|
68
|
+
voiceai.onAgentStateChange((state) => {
|
|
69
|
+
console.log('Agent is:', state.state);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Audio levels (for visualizations)
|
|
73
|
+
voiceai.onAudioLevel((level) => {
|
|
74
|
+
console.log('Level:', level.level, 'Speaking:', level.isSpeaking);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Errors
|
|
78
|
+
voiceai.onError((error) => {
|
|
79
|
+
console.error('Error:', error.message);
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Microphone Control
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
await voiceai.setMicrophoneEnabled(true); // Enable
|
|
87
|
+
await voiceai.setMicrophoneEnabled(false); // Disable
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Send Text Message
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
await voiceai.sendMessage('Hello agent!');
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Disconnect
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
await voiceai.disconnect();
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Agent Management
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
// List agents
|
|
106
|
+
const agents = await voiceai.agents.list();
|
|
107
|
+
|
|
108
|
+
// Create an agent
|
|
109
|
+
const agent = await voiceai.agents.create({
|
|
110
|
+
name: 'Customer Support',
|
|
111
|
+
config: {
|
|
112
|
+
prompt: 'You are a helpful customer support agent.',
|
|
113
|
+
greeting: 'Hello! How can I help you today?',
|
|
114
|
+
tts_params: {
|
|
115
|
+
voice_id: 'my-voice-id',
|
|
116
|
+
model: 'voiceai-tts-multilingual-v1-latest',
|
|
117
|
+
language: 'en'
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Deploy the agent
|
|
123
|
+
await voiceai.agents.deploy(agent.agent_id);
|
|
124
|
+
|
|
125
|
+
// Update an agent
|
|
126
|
+
await voiceai.agents.update(agent.agent_id, {
|
|
127
|
+
name: 'Updated Name'
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Pause an agent
|
|
131
|
+
await voiceai.agents.pause(agent.agent_id);
|
|
132
|
+
|
|
133
|
+
// Delete an agent
|
|
134
|
+
await voiceai.agents.disable(agent.agent_id);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Analytics
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
// Get call history
|
|
141
|
+
const history = await voiceai.analytics.getCallHistory({
|
|
142
|
+
page: 1,
|
|
143
|
+
limit: 20,
|
|
144
|
+
agent_ids: ['agent-123']
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Get transcript URL
|
|
148
|
+
const transcript = await voiceai.analytics.getTranscriptUrl(summaryId);
|
|
149
|
+
|
|
150
|
+
// Get stats summary
|
|
151
|
+
const stats = await voiceai.analytics.getStatsSummary();
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Knowledge Base
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
// Create a knowledge base
|
|
158
|
+
const kb = await voiceai.knowledgeBase.create({
|
|
159
|
+
name: 'Product FAQ',
|
|
160
|
+
documents: [
|
|
161
|
+
{ content: 'Return policy: 30 days for full refund.' },
|
|
162
|
+
{ content: 'Shipping: Free on orders over $50.' }
|
|
163
|
+
]
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Assign to an agent
|
|
167
|
+
await voiceai.agents.assignKnowledgeBase(agentId, kb.kb_id);
|
|
168
|
+
|
|
169
|
+
// List knowledge bases
|
|
170
|
+
const kbs = await voiceai.knowledgeBase.list();
|
|
171
|
+
|
|
172
|
+
// Update a knowledge base
|
|
173
|
+
await voiceai.knowledgeBase.update(kb.kb_id, {
|
|
174
|
+
documents: [{ content: 'Updated content' }]
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// Delete a knowledge base
|
|
178
|
+
await voiceai.knowledgeBase.remove(kb.kb_id);
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Phone Numbers
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
// Search available numbers
|
|
185
|
+
const numbers = await voiceai.phoneNumbers.search({
|
|
186
|
+
country_code: 'US',
|
|
187
|
+
area_code: '415'
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// Select a number
|
|
191
|
+
await voiceai.phoneNumbers.select('+14155551234');
|
|
192
|
+
|
|
193
|
+
// List your numbers
|
|
194
|
+
const myNumbers = await voiceai.phoneNumbers.list();
|
|
195
|
+
|
|
196
|
+
// Release a number
|
|
197
|
+
await voiceai.phoneNumbers.release('+14155551234');
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## TypeScript
|
|
201
|
+
|
|
202
|
+
Full TypeScript support with exported types:
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import VoiceAI, {
|
|
206
|
+
type Agent,
|
|
207
|
+
type TranscriptionSegment,
|
|
208
|
+
type ConnectionStatus,
|
|
209
|
+
type TTSParams,
|
|
210
|
+
} from '@voice-ai-labs/web-sdk';
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Browser Support
|
|
214
|
+
|
|
215
|
+
Chrome, Firefox, Safari (latest versions). Requires microphone permission for voice features.
|
|
216
|
+
|
|
217
|
+
## License
|
|
218
|
+
|
|
219
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/__tests__/setup.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
// Mock fetch globally
|
|
3
|
+
global.fetch = vi.fn();
|
|
4
|
+
// Mock window for browser environment detection
|
|
5
|
+
Object.defineProperty(global, 'window', {
|
|
6
|
+
value: {
|
|
7
|
+
location: {
|
|
8
|
+
origin: 'http://localhost:3000',
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
writable: true,
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/__tests__/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,sBAAsB;AACtB,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;AAEvB,gDAAgD;AAChD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE;IACtC,KAAK,EAAE;QACL,QAAQ,EAAE;YACR,MAAM,EAAE,uBAAuB;SAChC;KACF;IACD,QAAQ,EAAE,IAAI;CACf,CAAC,CAAC"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Management Client
|
|
3
|
+
*
|
|
4
|
+
* Provides methods for:
|
|
5
|
+
* - Creating, updating, and deleting agents
|
|
6
|
+
* - Deploying and pausing agents
|
|
7
|
+
* - Checking agent connection status
|
|
8
|
+
* - Managing agent knowledge bases
|
|
9
|
+
*/
|
|
10
|
+
import { BaseClient, BaseClientConfig } from './base';
|
|
11
|
+
import type { Agent, CreateAgentRequest, UpdateAgentRequest, AgentDeployResponse, AgentPauseResponse, AgentDeleteResponse, AgentConnectionStatusResponse, InitAgentRequest, InitAgentResponse, PaginatedAgentResponse, ListAgentsOptions } from '../types';
|
|
12
|
+
/**
|
|
13
|
+
* Client for Agent management operations
|
|
14
|
+
*/
|
|
15
|
+
export declare class AgentClient extends BaseClient {
|
|
16
|
+
constructor(config: BaseClientConfig);
|
|
17
|
+
/**
|
|
18
|
+
* List agents with optional pagination and filtering
|
|
19
|
+
*
|
|
20
|
+
* @param options - Pagination and filter options
|
|
21
|
+
* @returns Paginated list of agents or array of agents
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // Get all deployed agents
|
|
26
|
+
* const result = await client.agents.list({
|
|
27
|
+
* page: 1,
|
|
28
|
+
* limit: 10,
|
|
29
|
+
* show_statuses: ['deployed']
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* for (const agent of result.items) {
|
|
33
|
+
* console.log(`${agent.name}: ${agent.status}`);
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
list(options?: ListAgentsOptions): Promise<PaginatedAgentResponse | Agent[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Create a new agent
|
|
40
|
+
*
|
|
41
|
+
* @param options - Agent creation options
|
|
42
|
+
* @returns Created agent
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const agent = await client.agents.create({
|
|
47
|
+
* name: 'Customer Support Agent',
|
|
48
|
+
* config: {
|
|
49
|
+
* prompt: 'You are a helpful customer support agent.',
|
|
50
|
+
* greeting: 'Hello! How can I help you today?',
|
|
51
|
+
* tts_params: {
|
|
52
|
+
* voice_id: 'my-voice-id'
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* console.log('Created agent:', agent.agent_id);
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
create(options: CreateAgentRequest): Promise<Agent>;
|
|
61
|
+
/**
|
|
62
|
+
* Get agent details by ID
|
|
63
|
+
*
|
|
64
|
+
* @param agentId - The agent ID
|
|
65
|
+
* @returns Agent details
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const agent = await client.agents.getById('agent-123');
|
|
70
|
+
* console.log('Agent config:', agent.config);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
getById(agentId: string): Promise<Agent>;
|
|
74
|
+
/**
|
|
75
|
+
* Update an existing agent
|
|
76
|
+
*
|
|
77
|
+
* @param agentId - The agent ID to update
|
|
78
|
+
* @param options - Fields to update
|
|
79
|
+
* @returns Updated agent
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const updated = await client.agents.update('agent-123', {
|
|
84
|
+
* name: 'Updated Agent Name',
|
|
85
|
+
* config: {
|
|
86
|
+
* greeting: 'Hi there! What can I do for you?'
|
|
87
|
+
* }
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
update(agentId: string, options: UpdateAgentRequest): Promise<Agent>;
|
|
92
|
+
/**
|
|
93
|
+
* Deploy an agent (prepare for phone calls)
|
|
94
|
+
*
|
|
95
|
+
* @param agentId - The agent ID to deploy
|
|
96
|
+
* @returns Deployment response with agent and status
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const result = await client.agents.deploy('agent-123');
|
|
101
|
+
* console.log('Deployed:', result.message);
|
|
102
|
+
* console.log('SIP status:', result.sip_status);
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
deploy(agentId: string): Promise<AgentDeployResponse>;
|
|
106
|
+
/**
|
|
107
|
+
* Pause an agent (frees phone number)
|
|
108
|
+
*
|
|
109
|
+
* This endpoint is idempotent.
|
|
110
|
+
*
|
|
111
|
+
* @param agentId - The agent ID to pause
|
|
112
|
+
* @returns Pause response with agent
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const result = await client.agents.pause('agent-123');
|
|
117
|
+
* console.log('Agent status:', result.agent.status);
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
pause(agentId: string): Promise<AgentPauseResponse>;
|
|
121
|
+
/**
|
|
122
|
+
* Delete/disable an agent
|
|
123
|
+
*
|
|
124
|
+
* An agent must be paused before being deleted.
|
|
125
|
+
* Disabled agents will be automatically deleted after a grace period.
|
|
126
|
+
*
|
|
127
|
+
* @param agentId - The agent ID to delete
|
|
128
|
+
* @returns Delete response
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* // First pause, then delete
|
|
133
|
+
* await client.agents.pause('agent-123');
|
|
134
|
+
* const result = await client.agents.disable('agent-123');
|
|
135
|
+
* console.log('Deleted:', result.message);
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
disable(agentId: string): Promise<AgentDeleteResponse>;
|
|
139
|
+
/**
|
|
140
|
+
* Initialize agent from template
|
|
141
|
+
*
|
|
142
|
+
* @param options - Template options
|
|
143
|
+
* @returns Template configuration and available types
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* // Get available templates
|
|
148
|
+
* const result = await client.agents.initFromTemplate();
|
|
149
|
+
* console.log('Available types:', result.available_types);
|
|
150
|
+
*
|
|
151
|
+
* // Initialize from specific template
|
|
152
|
+
* const template = await client.agents.initFromTemplate({
|
|
153
|
+
* agent_template: 'customer_support'
|
|
154
|
+
* });
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
initFromTemplate(options?: InitAgentRequest): Promise<InitAgentResponse>;
|
|
158
|
+
/**
|
|
159
|
+
* Check if an agent is available for connection
|
|
160
|
+
*
|
|
161
|
+
* @param agentId - The agent ID to check
|
|
162
|
+
* @returns Agent connection status
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* const status = await client.agents.getStatus('agent-123');
|
|
167
|
+
*
|
|
168
|
+
* if (status.call_allowed) {
|
|
169
|
+
* console.log('Agent is available for calls');
|
|
170
|
+
* } else {
|
|
171
|
+
* console.log('Reason:', status.call_validation_details);
|
|
172
|
+
* }
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
getStatus(agentId: string): Promise<AgentConnectionStatusResponse>;
|
|
176
|
+
/**
|
|
177
|
+
* Assign a knowledge base to an agent for RAG
|
|
178
|
+
*
|
|
179
|
+
* @param agentId - The agent ID
|
|
180
|
+
* @param kbId - The knowledge base ID to assign
|
|
181
|
+
* @returns Updated agent
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* const agent = await client.agents.assignKnowledgeBase('agent-123', 42);
|
|
186
|
+
* console.log('KB assigned:', agent.kb_id);
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
assignKnowledgeBase(agentId: string, kbId: number): Promise<Agent>;
|
|
190
|
+
/**
|
|
191
|
+
* Remove knowledge base from an agent
|
|
192
|
+
*
|
|
193
|
+
* @param agentId - The agent ID
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* await client.agents.unassignKnowledgeBase('agent-123');
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
unassignKnowledgeBase(agentId: string): Promise<void>;
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/client/agents.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,KAAK,EACV,KAAK,EACL,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,6BAA6B,EAC7B,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,iBAAiB,EAElB,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,qBAAa,WAAY,SAAQ,UAAU;gBAC7B,MAAM,EAAE,gBAAgB;IAIpC;;;;;;;;;;;;;;;;;;;OAmBG;IACG,IAAI,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,sBAAsB,GAAG,KAAK,EAAE,CAAC;IAUlF;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,MAAM,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,KAAK,CAAC;IAIzD;;;;;;;;;;;OAWG;IACG,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAI9C;;;;;;;;;;;;;;;;OAgBG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,KAAK,CAAC;IAI1E;;;;;;;;;;;;OAYG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAI3D;;;;;;;;;;;;;OAaG;IACG,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIzD;;;;;;;;;;;;;;;;OAgBG;IACG,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAI5D;;;;;;;;;;;;;;;;;OAiBG;IACG,gBAAgB,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAI9E;;;;;;;;;;;;;;;;OAgBG;IACG,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,6BAA6B,CAAC;IAIxE;;;;;;;;;;;;OAYG;IACG,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAKxE;;;;;;;;;OASG;IACG,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG5D"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Management Client
|
|
3
|
+
*
|
|
4
|
+
* Provides methods for:
|
|
5
|
+
* - Creating, updating, and deleting agents
|
|
6
|
+
* - Deploying and pausing agents
|
|
7
|
+
* - Checking agent connection status
|
|
8
|
+
* - Managing agent knowledge bases
|
|
9
|
+
*/
|
|
10
|
+
import { BaseClient } from './base';
|
|
11
|
+
/**
|
|
12
|
+
* Client for Agent management operations
|
|
13
|
+
*/
|
|
14
|
+
export class AgentClient extends BaseClient {
|
|
15
|
+
constructor(config) {
|
|
16
|
+
super(config);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* List agents with optional pagination and filtering
|
|
20
|
+
*
|
|
21
|
+
* @param options - Pagination and filter options
|
|
22
|
+
* @returns Paginated list of agents or array of agents
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Get all deployed agents
|
|
27
|
+
* const result = await client.agents.list({
|
|
28
|
+
* page: 1,
|
|
29
|
+
* limit: 10,
|
|
30
|
+
* show_statuses: ['deployed']
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* for (const agent of result.items) {
|
|
34
|
+
* console.log(`${agent.name}: ${agent.status}`);
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
async list(options) {
|
|
39
|
+
const params = {};
|
|
40
|
+
if (options?.page !== undefined)
|
|
41
|
+
params.page = options.page;
|
|
42
|
+
if (options?.limit !== undefined)
|
|
43
|
+
params.limit = options.limit;
|
|
44
|
+
if (options?.show_statuses)
|
|
45
|
+
params.show_statuses = options.show_statuses;
|
|
46
|
+
return super.get('/agent/', params);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create a new agent
|
|
50
|
+
*
|
|
51
|
+
* @param options - Agent creation options
|
|
52
|
+
* @returns Created agent
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const agent = await client.agents.create({
|
|
57
|
+
* name: 'Customer Support Agent',
|
|
58
|
+
* config: {
|
|
59
|
+
* prompt: 'You are a helpful customer support agent.',
|
|
60
|
+
* greeting: 'Hello! How can I help you today?',
|
|
61
|
+
* tts_params: {
|
|
62
|
+
* voice_id: 'my-voice-id'
|
|
63
|
+
* }
|
|
64
|
+
* }
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* console.log('Created agent:', agent.agent_id);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
async create(options) {
|
|
71
|
+
return this.post('/agent/', options);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get agent details by ID
|
|
75
|
+
*
|
|
76
|
+
* @param agentId - The agent ID
|
|
77
|
+
* @returns Agent details
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const agent = await client.agents.getById('agent-123');
|
|
82
|
+
* console.log('Agent config:', agent.config);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
async getById(agentId) {
|
|
86
|
+
return super.get(`/agent/${encodeURIComponent(agentId)}`);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Update an existing agent
|
|
90
|
+
*
|
|
91
|
+
* @param agentId - The agent ID to update
|
|
92
|
+
* @param options - Fields to update
|
|
93
|
+
* @returns Updated agent
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const updated = await client.agents.update('agent-123', {
|
|
98
|
+
* name: 'Updated Agent Name',
|
|
99
|
+
* config: {
|
|
100
|
+
* greeting: 'Hi there! What can I do for you?'
|
|
101
|
+
* }
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
async update(agentId, options) {
|
|
106
|
+
return this.put(`/agent/${encodeURIComponent(agentId)}`, options);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Deploy an agent (prepare for phone calls)
|
|
110
|
+
*
|
|
111
|
+
* @param agentId - The agent ID to deploy
|
|
112
|
+
* @returns Deployment response with agent and status
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const result = await client.agents.deploy('agent-123');
|
|
117
|
+
* console.log('Deployed:', result.message);
|
|
118
|
+
* console.log('SIP status:', result.sip_status);
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
async deploy(agentId) {
|
|
122
|
+
return this.post(`/agent/${encodeURIComponent(agentId)}/deploy`);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Pause an agent (frees phone number)
|
|
126
|
+
*
|
|
127
|
+
* This endpoint is idempotent.
|
|
128
|
+
*
|
|
129
|
+
* @param agentId - The agent ID to pause
|
|
130
|
+
* @returns Pause response with agent
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const result = await client.agents.pause('agent-123');
|
|
135
|
+
* console.log('Agent status:', result.agent.status);
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
async pause(agentId) {
|
|
139
|
+
return this.post(`/agent/${encodeURIComponent(agentId)}/pause`);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Delete/disable an agent
|
|
143
|
+
*
|
|
144
|
+
* An agent must be paused before being deleted.
|
|
145
|
+
* Disabled agents will be automatically deleted after a grace period.
|
|
146
|
+
*
|
|
147
|
+
* @param agentId - The agent ID to delete
|
|
148
|
+
* @returns Delete response
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* // First pause, then delete
|
|
153
|
+
* await client.agents.pause('agent-123');
|
|
154
|
+
* const result = await client.agents.disable('agent-123');
|
|
155
|
+
* console.log('Deleted:', result.message);
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
async disable(agentId) {
|
|
159
|
+
return this.post(`/agent/${encodeURIComponent(agentId)}/disable`);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Initialize agent from template
|
|
163
|
+
*
|
|
164
|
+
* @param options - Template options
|
|
165
|
+
* @returns Template configuration and available types
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* // Get available templates
|
|
170
|
+
* const result = await client.agents.initFromTemplate();
|
|
171
|
+
* console.log('Available types:', result.available_types);
|
|
172
|
+
*
|
|
173
|
+
* // Initialize from specific template
|
|
174
|
+
* const template = await client.agents.initFromTemplate({
|
|
175
|
+
* agent_template: 'customer_support'
|
|
176
|
+
* });
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
async initFromTemplate(options) {
|
|
180
|
+
return this.post('/agent/init-agent', options || {});
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Check if an agent is available for connection
|
|
184
|
+
*
|
|
185
|
+
* @param agentId - The agent ID to check
|
|
186
|
+
* @returns Agent connection status
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* const status = await client.agents.getStatus('agent-123');
|
|
191
|
+
*
|
|
192
|
+
* if (status.call_allowed) {
|
|
193
|
+
* console.log('Agent is available for calls');
|
|
194
|
+
* } else {
|
|
195
|
+
* console.log('Reason:', status.call_validation_details);
|
|
196
|
+
* }
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
async getStatus(agentId) {
|
|
200
|
+
return super.get(`/connection/agent-status/${encodeURIComponent(agentId)}`);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Assign a knowledge base to an agent for RAG
|
|
204
|
+
*
|
|
205
|
+
* @param agentId - The agent ID
|
|
206
|
+
* @param kbId - The knowledge base ID to assign
|
|
207
|
+
* @returns Updated agent
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* const agent = await client.agents.assignKnowledgeBase('agent-123', 42);
|
|
212
|
+
* console.log('KB assigned:', agent.kb_id);
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
async assignKnowledgeBase(agentId, kbId) {
|
|
216
|
+
const body = { kb_id: kbId };
|
|
217
|
+
return this.post(`/agent/${encodeURIComponent(agentId)}/assign-knowledge-base`, body);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Remove knowledge base from an agent
|
|
221
|
+
*
|
|
222
|
+
* @param agentId - The agent ID
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* await client.agents.unassignKnowledgeBase('agent-123');
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
async unassignKnowledgeBase(agentId) {
|
|
230
|
+
await this.delete(`/agent/${encodeURIComponent(agentId)}/knowledge-base`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=agents.js.map
|