@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../../src/client/agents.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAoB,MAAM,QAAQ,CAAC;AAgBtD;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,UAAU;IACzC,YAAY,MAAwB;QAClC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,CAAC,IAAI,CAAC,OAA2B;QACpC,MAAM,MAAM,GAAwB,EAAE,CAAC;QAEvC,IAAI,OAAO,EAAE,IAAI,KAAK,SAAS;YAAE,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC5D,IAAI,OAAO,EAAE,KAAK,KAAK,SAAS;YAAE,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC/D,IAAI,OAAO,EAAE,aAAa;YAAE,MAAM,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAEzE,OAAO,KAAK,CAAC,GAAG,CAAmC,SAAS,EAAE,MAAM,CAAC,CAAC;IACxE,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,KAAK,CAAC,MAAM,CAAC,OAA2B;QACtC,OAAO,IAAI,CAAC,IAAI,CAAQ,SAAS,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,OAAO,CAAC,OAAe;QAC3B,OAAO,KAAK,CAAC,GAAG,CAAQ,UAAU,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACnE,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,MAAM,CAA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KAAK,CAAC,qBAAqB,CAAC,OAAe;QACzC,MAAM,IAAI,CAAC,MAAM,CAAO,UAAU,kBAAkB,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAClF,CAAC;CACF"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics Client
|
|
3
|
+
*
|
|
4
|
+
* Provides methods for:
|
|
5
|
+
* - Getting call history with filters
|
|
6
|
+
* - Getting transcript URLs
|
|
7
|
+
* - Getting agent stats summary
|
|
8
|
+
*/
|
|
9
|
+
import { BaseClient, BaseClientConfig } from './base';
|
|
10
|
+
import type { PaginatedCallHistoryResponse, GetCallHistoryOptions, TranscriptResponse, AgentStatsSummaryResponse } from '../types';
|
|
11
|
+
/**
|
|
12
|
+
* Client for analytics and reporting operations
|
|
13
|
+
*/
|
|
14
|
+
export declare class AnalyticsClient extends BaseClient {
|
|
15
|
+
constructor(config: BaseClientConfig);
|
|
16
|
+
/**
|
|
17
|
+
* Get call history with optional filters
|
|
18
|
+
*
|
|
19
|
+
* @param options - Pagination and filter options
|
|
20
|
+
* @returns Paginated call history
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // Get recent calls
|
|
25
|
+
* const history = await client.analytics.getCallHistory({
|
|
26
|
+
* page: 1,
|
|
27
|
+
* limit: 20
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* for (const call of history.items) {
|
|
31
|
+
* console.log(`Call ${call.id}: ${call.call_duration_seconds}s`);
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // Filter by date range and agent
|
|
38
|
+
* const history = await client.analytics.getCallHistory({
|
|
39
|
+
* start_date: '2024-01-01T00:00:00+00:00',
|
|
40
|
+
* end_date: '2024-01-31T23:59:59+00:00',
|
|
41
|
+
* agent_ids: ['agent-123', 'agent-456']
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
getCallHistory(options?: GetCallHistoryOptions): Promise<PaginatedCallHistoryResponse>;
|
|
46
|
+
/**
|
|
47
|
+
* Get transcript download URL for a call
|
|
48
|
+
*
|
|
49
|
+
* @param summaryId - The call summary ID
|
|
50
|
+
* @returns Object with transcript URL
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const { url } = await client.analytics.getTranscriptUrl(12345);
|
|
55
|
+
*
|
|
56
|
+
* // Download transcript
|
|
57
|
+
* window.open(url, '_blank');
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
getTranscriptUrl(summaryId: number): Promise<TranscriptResponse>;
|
|
61
|
+
/**
|
|
62
|
+
* Get agent stats summary
|
|
63
|
+
*
|
|
64
|
+
* @returns Summary of agent counts by status
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const stats = await client.analytics.getStatsSummary();
|
|
69
|
+
*
|
|
70
|
+
* console.log('Total agents:', stats.total_agents);
|
|
71
|
+
* console.log('Deployed:', stats.status_summary.deployed);
|
|
72
|
+
* console.log('Paused:', stats.status_summary.paused);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
getStatsSummary(): Promise<AgentStatsSummaryResponse>;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=analytics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../src/client/analytics.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,KAAK,EACV,4BAA4B,EAC5B,qBAAqB,EACrB,kBAAkB,EAClB,yBAAyB,EAC1B,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,qBAAa,eAAgB,SAAQ,UAAU;gBACjC,MAAM,EAAE,gBAAgB;IAIpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,cAAc,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,4BAA4B,CAAC;IAY5F;;;;;;;;;;;;;OAaG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAItE;;;;;;;;;;;;;OAaG;IACG,eAAe,IAAI,OAAO,CAAC,yBAAyB,CAAC;CAG5D"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics Client
|
|
3
|
+
*
|
|
4
|
+
* Provides methods for:
|
|
5
|
+
* - Getting call history with filters
|
|
6
|
+
* - Getting transcript URLs
|
|
7
|
+
* - Getting agent stats summary
|
|
8
|
+
*/
|
|
9
|
+
import { BaseClient } from './base';
|
|
10
|
+
/**
|
|
11
|
+
* Client for analytics and reporting operations
|
|
12
|
+
*/
|
|
13
|
+
export class AnalyticsClient extends BaseClient {
|
|
14
|
+
constructor(config) {
|
|
15
|
+
super(config);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get call history with optional filters
|
|
19
|
+
*
|
|
20
|
+
* @param options - Pagination and filter options
|
|
21
|
+
* @returns Paginated call history
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // Get recent calls
|
|
26
|
+
* const history = await client.analytics.getCallHistory({
|
|
27
|
+
* page: 1,
|
|
28
|
+
* limit: 20
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* for (const call of history.items) {
|
|
32
|
+
* console.log(`Call ${call.id}: ${call.call_duration_seconds}s`);
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // Filter by date range and agent
|
|
39
|
+
* const history = await client.analytics.getCallHistory({
|
|
40
|
+
* start_date: '2024-01-01T00:00:00+00:00',
|
|
41
|
+
* end_date: '2024-01-31T23:59:59+00:00',
|
|
42
|
+
* agent_ids: ['agent-123', 'agent-456']
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
async getCallHistory(options) {
|
|
47
|
+
const params = {};
|
|
48
|
+
if (options?.page !== undefined)
|
|
49
|
+
params.page = options.page;
|
|
50
|
+
if (options?.limit !== undefined)
|
|
51
|
+
params.limit = options.limit;
|
|
52
|
+
if (options?.start_date)
|
|
53
|
+
params.start_date = options.start_date;
|
|
54
|
+
if (options?.end_date)
|
|
55
|
+
params.end_date = options.end_date;
|
|
56
|
+
if (options?.agent_ids)
|
|
57
|
+
params.agent_ids = options.agent_ids;
|
|
58
|
+
return this.get('/agent/call-history', params);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get transcript download URL for a call
|
|
62
|
+
*
|
|
63
|
+
* @param summaryId - The call summary ID
|
|
64
|
+
* @returns Object with transcript URL
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const { url } = await client.analytics.getTranscriptUrl(12345);
|
|
69
|
+
*
|
|
70
|
+
* // Download transcript
|
|
71
|
+
* window.open(url, '_blank');
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
async getTranscriptUrl(summaryId) {
|
|
75
|
+
return this.get(`/agent/call-history/${summaryId}/transcript`);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get agent stats summary
|
|
79
|
+
*
|
|
80
|
+
* @returns Summary of agent counts by status
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const stats = await client.analytics.getStatsSummary();
|
|
85
|
+
*
|
|
86
|
+
* console.log('Total agents:', stats.total_agents);
|
|
87
|
+
* console.log('Deployed:', stats.status_summary.deployed);
|
|
88
|
+
* console.log('Paused:', stats.status_summary.paused);
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
async getStatsSummary() {
|
|
92
|
+
return this.get('/agent/stats-summary');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=analytics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["../../src/client/analytics.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAoB,MAAM,QAAQ,CAAC;AAQtD;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,UAAU;IAC7C,YAAY,MAAwB;QAClC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,KAAK,CAAC,cAAc,CAAC,OAA+B;QAClD,MAAM,MAAM,GAAwB,EAAE,CAAC;QAEvC,IAAI,OAAO,EAAE,IAAI,KAAK,SAAS;YAAE,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC5D,IAAI,OAAO,EAAE,KAAK,KAAK,SAAS;YAAE,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC/D,IAAI,OAAO,EAAE,UAAU;YAAE,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QAChE,IAAI,OAAO,EAAE,QAAQ;YAAE,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAC1D,IAAI,OAAO,EAAE,SAAS;YAAE,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QAE7D,OAAO,IAAI,CAAC,GAAG,CAA+B,qBAAqB,EAAE,MAAM,CAAC,CAAC;IAC/E,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,gBAAgB,CAAC,SAAiB;QACtC,OAAO,IAAI,CAAC,GAAG,CAAqB,uBAAuB,SAAS,aAAa,CAAC,CAAC;IACrF,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,eAAe;QACnB,OAAO,IAAI,CAAC,GAAG,CAA4B,sBAAsB,CAAC,CAAC;IACrE,CAAC;CACF"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base HTTP Client for Voice.AI API
|
|
3
|
+
*
|
|
4
|
+
* Provides common functionality for all API clients including:
|
|
5
|
+
* - Authentication via Bearer token
|
|
6
|
+
* - Error handling and response parsing
|
|
7
|
+
* - Common HTTP methods (GET, POST, PUT, PATCH, DELETE)
|
|
8
|
+
*/
|
|
9
|
+
/** Error thrown by Voice.AI API client */
|
|
10
|
+
export declare class VoiceAIError extends Error {
|
|
11
|
+
readonly status?: number | undefined;
|
|
12
|
+
readonly code?: string | undefined;
|
|
13
|
+
readonly detail?: string | undefined;
|
|
14
|
+
constructor(message: string, status?: number | undefined, code?: string | undefined, detail?: string | undefined);
|
|
15
|
+
}
|
|
16
|
+
/** Configuration for BaseClient */
|
|
17
|
+
export interface BaseClientConfig {
|
|
18
|
+
apiKey: string;
|
|
19
|
+
apiUrl: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Base HTTP client with authentication and error handling
|
|
23
|
+
*/
|
|
24
|
+
export declare class BaseClient {
|
|
25
|
+
protected readonly apiKey: string;
|
|
26
|
+
protected readonly apiUrl: string;
|
|
27
|
+
constructor(config: BaseClientConfig);
|
|
28
|
+
/**
|
|
29
|
+
* Build headers with authentication
|
|
30
|
+
*/
|
|
31
|
+
protected getHeaders(contentType?: string): Record<string, string>;
|
|
32
|
+
/**
|
|
33
|
+
* Handle API response and parse errors
|
|
34
|
+
*/
|
|
35
|
+
protected handleResponse<T>(response: Response): Promise<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Perform GET request
|
|
38
|
+
*/
|
|
39
|
+
protected get<T>(path: string, params?: Record<string, any>): Promise<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Perform POST request
|
|
42
|
+
*/
|
|
43
|
+
protected post<T>(path: string, body?: any): Promise<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Perform POST request with FormData (for file uploads)
|
|
46
|
+
*/
|
|
47
|
+
protected postFormData<T>(path: string, formData: FormData): Promise<T>;
|
|
48
|
+
/**
|
|
49
|
+
* Perform PUT request
|
|
50
|
+
*/
|
|
51
|
+
protected put<T>(path: string, body?: any): Promise<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Perform PATCH request
|
|
54
|
+
*/
|
|
55
|
+
protected patch<T>(path: string, body?: any): Promise<T>;
|
|
56
|
+
/**
|
|
57
|
+
* Perform DELETE request
|
|
58
|
+
*/
|
|
59
|
+
protected delete<T>(path: string): Promise<T>;
|
|
60
|
+
/**
|
|
61
|
+
* Perform POST request that returns binary data (Blob)
|
|
62
|
+
*/
|
|
63
|
+
protected postForBlob(path: string, body?: any): Promise<Blob>;
|
|
64
|
+
/**
|
|
65
|
+
* Perform POST request that returns a streaming Response
|
|
66
|
+
*/
|
|
67
|
+
protected postForStream(path: string, body?: any): Promise<Response>;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/client/base.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,0CAA0C;AAC1C,qBAAa,YAAa,SAAQ,KAAK;aAGnB,MAAM,CAAC,EAAE,MAAM;aACf,IAAI,CAAC,EAAE,MAAM;aACb,MAAM,CAAC,EAAE,MAAM;gBAH/B,OAAO,EAAE,MAAM,EACC,MAAM,CAAC,EAAE,MAAM,YAAA,EACf,IAAI,CAAC,EAAE,MAAM,YAAA,EACb,MAAM,CAAC,EAAE,MAAM,YAAA;CAKlC;AAED,mCAAmC;AACnC,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,qBAAa,UAAU;IACrB,SAAS,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AAE,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC;CAyB3E"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base HTTP Client for Voice.AI API
|
|
3
|
+
*
|
|
4
|
+
* Provides common functionality for all API clients including:
|
|
5
|
+
* - Authentication via Bearer token
|
|
6
|
+
* - Error handling and response parsing
|
|
7
|
+
* - Common HTTP methods (GET, POST, PUT, PATCH, DELETE)
|
|
8
|
+
*/
|
|
9
|
+
/** Error thrown by Voice.AI API client */
|
|
10
|
+
export class VoiceAIError extends Error {
|
|
11
|
+
constructor(message, status, code, detail) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.detail = detail;
|
|
16
|
+
this.name = 'VoiceAIError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Base HTTP client with authentication and error handling
|
|
21
|
+
*/
|
|
22
|
+
export class BaseClient {
|
|
23
|
+
constructor(config) {
|
|
24
|
+
this.apiKey = config.apiKey;
|
|
25
|
+
this.apiUrl = config.apiUrl;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Build headers with authentication
|
|
29
|
+
*/
|
|
30
|
+
getHeaders(contentType = 'application/json') {
|
|
31
|
+
const headers = {
|
|
32
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
33
|
+
};
|
|
34
|
+
if (contentType) {
|
|
35
|
+
headers['Content-Type'] = contentType;
|
|
36
|
+
}
|
|
37
|
+
return headers;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Handle API response and parse errors
|
|
41
|
+
*/
|
|
42
|
+
async handleResponse(response) {
|
|
43
|
+
if (response.ok) {
|
|
44
|
+
// Check if response has content
|
|
45
|
+
const contentType = response.headers.get('content-type');
|
|
46
|
+
if (contentType?.includes('application/json')) {
|
|
47
|
+
return response.json();
|
|
48
|
+
}
|
|
49
|
+
// For 204 No Content or non-JSON responses
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
// Parse error response
|
|
53
|
+
let errorData = null;
|
|
54
|
+
try {
|
|
55
|
+
errorData = await response.json();
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// Response body might not be JSON
|
|
59
|
+
}
|
|
60
|
+
// Handle specific error codes
|
|
61
|
+
if (response.status === 401) {
|
|
62
|
+
throw new VoiceAIError('Authentication failed. Please check your API key.', 401, 'UNAUTHORIZED');
|
|
63
|
+
}
|
|
64
|
+
if (response.status === 403) {
|
|
65
|
+
const detail = errorData?.detail || errorData?.error;
|
|
66
|
+
const code = errorData?.code;
|
|
67
|
+
throw new VoiceAIError(detail || 'Forbidden - insufficient permissions', 403, code || 'FORBIDDEN', detail);
|
|
68
|
+
}
|
|
69
|
+
if (response.status === 404) {
|
|
70
|
+
const detail = errorData?.detail || errorData?.error;
|
|
71
|
+
throw new VoiceAIError(detail || 'Resource not found', 404, 'NOT_FOUND', detail);
|
|
72
|
+
}
|
|
73
|
+
if (response.status === 422) {
|
|
74
|
+
const validationError = errorData;
|
|
75
|
+
const detail = validationError?.detail?.[0]?.msg || 'Validation error';
|
|
76
|
+
throw new VoiceAIError(detail, 422, 'VALIDATION_ERROR', JSON.stringify(validationError?.detail));
|
|
77
|
+
}
|
|
78
|
+
// Generic error
|
|
79
|
+
const errorMsg = errorData?.error ||
|
|
80
|
+
errorData?.detail ||
|
|
81
|
+
`Request failed with status ${response.status}`;
|
|
82
|
+
throw new VoiceAIError(errorMsg, response.status, errorData?.code);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Perform GET request
|
|
86
|
+
*/
|
|
87
|
+
async get(path, params) {
|
|
88
|
+
const url = new URL(`${this.apiUrl}${path}`);
|
|
89
|
+
if (params) {
|
|
90
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
91
|
+
if (value !== undefined && value !== null) {
|
|
92
|
+
if (Array.isArray(value)) {
|
|
93
|
+
value.forEach(v => url.searchParams.append(key, String(v)));
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
url.searchParams.append(key, String(value));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const response = await fetch(url.toString(), {
|
|
102
|
+
method: 'GET',
|
|
103
|
+
headers: this.getHeaders(),
|
|
104
|
+
});
|
|
105
|
+
return this.handleResponse(response);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Perform POST request
|
|
109
|
+
*/
|
|
110
|
+
async post(path, body) {
|
|
111
|
+
const response = await fetch(`${this.apiUrl}${path}`, {
|
|
112
|
+
method: 'POST',
|
|
113
|
+
headers: this.getHeaders(),
|
|
114
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
115
|
+
});
|
|
116
|
+
return this.handleResponse(response);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Perform POST request with FormData (for file uploads)
|
|
120
|
+
*/
|
|
121
|
+
async postFormData(path, formData) {
|
|
122
|
+
// Don't set Content-Type header - browser will set it with boundary
|
|
123
|
+
const headers = {
|
|
124
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
125
|
+
};
|
|
126
|
+
const response = await fetch(`${this.apiUrl}${path}`, {
|
|
127
|
+
method: 'POST',
|
|
128
|
+
headers,
|
|
129
|
+
body: formData,
|
|
130
|
+
});
|
|
131
|
+
return this.handleResponse(response);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Perform PUT request
|
|
135
|
+
*/
|
|
136
|
+
async put(path, body) {
|
|
137
|
+
const response = await fetch(`${this.apiUrl}${path}`, {
|
|
138
|
+
method: 'PUT',
|
|
139
|
+
headers: this.getHeaders(),
|
|
140
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
141
|
+
});
|
|
142
|
+
return this.handleResponse(response);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Perform PATCH request
|
|
146
|
+
*/
|
|
147
|
+
async patch(path, body) {
|
|
148
|
+
const response = await fetch(`${this.apiUrl}${path}`, {
|
|
149
|
+
method: 'PATCH',
|
|
150
|
+
headers: this.getHeaders(),
|
|
151
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
152
|
+
});
|
|
153
|
+
return this.handleResponse(response);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Perform DELETE request
|
|
157
|
+
*/
|
|
158
|
+
async delete(path) {
|
|
159
|
+
const response = await fetch(`${this.apiUrl}${path}`, {
|
|
160
|
+
method: 'DELETE',
|
|
161
|
+
headers: this.getHeaders(),
|
|
162
|
+
});
|
|
163
|
+
return this.handleResponse(response);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Perform POST request that returns binary data (Blob)
|
|
167
|
+
*/
|
|
168
|
+
async postForBlob(path, body) {
|
|
169
|
+
const response = await fetch(`${this.apiUrl}${path}`, {
|
|
170
|
+
method: 'POST',
|
|
171
|
+
headers: this.getHeaders(),
|
|
172
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
173
|
+
});
|
|
174
|
+
if (!response.ok) {
|
|
175
|
+
// Try to parse error from JSON
|
|
176
|
+
let errorData = null;
|
|
177
|
+
try {
|
|
178
|
+
errorData = await response.json();
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
// Not JSON
|
|
182
|
+
}
|
|
183
|
+
throw new VoiceAIError(errorData?.error || errorData?.detail || `Request failed with status ${response.status}`, response.status, errorData?.code);
|
|
184
|
+
}
|
|
185
|
+
return response.blob();
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Perform POST request that returns a streaming Response
|
|
189
|
+
*/
|
|
190
|
+
async postForStream(path, body) {
|
|
191
|
+
const response = await fetch(`${this.apiUrl}${path}`, {
|
|
192
|
+
method: 'POST',
|
|
193
|
+
headers: this.getHeaders(),
|
|
194
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
195
|
+
});
|
|
196
|
+
if (!response.ok) {
|
|
197
|
+
// Try to parse error from JSON
|
|
198
|
+
let errorData = null;
|
|
199
|
+
try {
|
|
200
|
+
errorData = await response.json();
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
// Not JSON
|
|
204
|
+
}
|
|
205
|
+
throw new VoiceAIError(errorData?.error || errorData?.detail || `Request failed with status ${response.status}`, response.status, errorData?.code);
|
|
206
|
+
}
|
|
207
|
+
return response;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/client/base.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,0CAA0C;AAC1C,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YACE,OAAe,EACC,MAAe,EACf,IAAa,EACb,MAAe;QAE/B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,WAAM,GAAN,MAAM,CAAS;QACf,SAAI,GAAJ,IAAI,CAAS;QACb,WAAM,GAAN,MAAM,CAAS;QAG/B,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAQD;;GAEG;AACH,MAAM,OAAO,UAAU;IAIrB,YAAY,MAAwB;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED;;OAEG;IACO,UAAU,CAAC,cAAsB,kBAAkB;QAC3D,MAAM,OAAO,GAA2B;YACtC,eAAe,EAAE,UAAU,IAAI,CAAC,MAAM,EAAE;SACzC,CAAC;QAEF,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,CAAC,cAAc,CAAC,GAAG,WAAW,CAAC;QACxC,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,cAAc,CAAI,QAAkB;QAClD,IAA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CAAC,MAAM,EAAE,EACxF,QAAQ,CAAC,MAAM,EACf,SAAS,EAAE,IAAI,CAChB,CAAC;QACJ,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VoiceAIClient - Main API Client for Voice.AI Agent API
|
|
3
|
+
*
|
|
4
|
+
* Provides access to Voice.AI Agent API functionality through sub-clients:
|
|
5
|
+
* - agents: Agent management (create, update, deploy, pause, delete)
|
|
6
|
+
* - analytics: Call history and stats
|
|
7
|
+
* - knowledgeBase: Knowledge base management for RAG
|
|
8
|
+
* - phoneNumbers: Phone number management
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { VoiceAIClient } from '@voice-ai-labs/web-sdk';
|
|
13
|
+
*
|
|
14
|
+
* const client = new VoiceAIClient({
|
|
15
|
+
* apiKey: 'vk_your_api_key'
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // List agents
|
|
19
|
+
* const agents = await client.agents.list();
|
|
20
|
+
*
|
|
21
|
+
* // Create and deploy an agent
|
|
22
|
+
* const agent = await client.agents.create({
|
|
23
|
+
* name: 'Support Agent',
|
|
24
|
+
* config: { prompt: 'You are a helpful assistant.' }
|
|
25
|
+
* });
|
|
26
|
+
* await client.agents.deploy(agent.agent_id);
|
|
27
|
+
*
|
|
28
|
+
* // Get call history
|
|
29
|
+
* const history = await client.analytics.getCallHistory();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
import type { VoiceAIClientConfig } from '../types';
|
|
33
|
+
import { AgentClient } from './agents';
|
|
34
|
+
import { AnalyticsClient } from './analytics';
|
|
35
|
+
import { KnowledgeBaseClient } from './knowledge-base';
|
|
36
|
+
import { PhoneNumberClient } from './phone-numbers';
|
|
37
|
+
export { VoiceAIError } from './base';
|
|
38
|
+
/**
|
|
39
|
+
* Main API client for Voice.AI Agent API
|
|
40
|
+
*/
|
|
41
|
+
export declare class VoiceAIClient {
|
|
42
|
+
/** Agent management client */
|
|
43
|
+
readonly agents: AgentClient;
|
|
44
|
+
/** Analytics client */
|
|
45
|
+
readonly analytics: AnalyticsClient;
|
|
46
|
+
/** Knowledge Base client */
|
|
47
|
+
readonly knowledgeBase: KnowledgeBaseClient;
|
|
48
|
+
/** Phone Number management client */
|
|
49
|
+
readonly phoneNumbers: PhoneNumberClient;
|
|
50
|
+
/** Default API URL */
|
|
51
|
+
private static readonly DEFAULT_API_URL;
|
|
52
|
+
/**
|
|
53
|
+
* Create a new VoiceAIClient
|
|
54
|
+
*
|
|
55
|
+
* @param config - Client configuration
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const client = new VoiceAIClient({
|
|
60
|
+
* apiKey: 'vk_your_api_key',
|
|
61
|
+
* apiUrl: 'https://custom-api.example.com/api/v1' // optional
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
constructor(config: VoiceAIClientConfig);
|
|
66
|
+
}
|
|
67
|
+
export { AgentClient } from './agents';
|
|
68
|
+
export { AnalyticsClient } from './analytics';
|
|
69
|
+
export { KnowledgeBaseClient } from './knowledge-base';
|
|
70
|
+
export { PhoneNumberClient } from './phone-numbers';
|
|
71
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC;;GAEG;AACH,qBAAa,aAAa;IACxB,8BAA8B;IAC9B,SAAgB,MAAM,EAAE,WAAW,CAAC;IAEpC,uBAAuB;IACvB,SAAgB,SAAS,EAAE,eAAe,CAAC;IAE3C,4BAA4B;IAC5B,SAAgB,aAAa,EAAE,mBAAmB,CAAC;IAEnD,qCAAqC;IACrC,SAAgB,YAAY,EAAE,iBAAiB,CAAC;IAEhD,sBAAsB;IACtB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAiC;IAExE;;;;;;;;;;;;OAYG;gBACS,MAAM,EAAE,mBAAmB;CAaxC;AAGD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VoiceAIClient - Main API Client for Voice.AI Agent API
|
|
3
|
+
*
|
|
4
|
+
* Provides access to Voice.AI Agent API functionality through sub-clients:
|
|
5
|
+
* - agents: Agent management (create, update, deploy, pause, delete)
|
|
6
|
+
* - analytics: Call history and stats
|
|
7
|
+
* - knowledgeBase: Knowledge base management for RAG
|
|
8
|
+
* - phoneNumbers: Phone number management
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { VoiceAIClient } from '@voice-ai-labs/web-sdk';
|
|
13
|
+
*
|
|
14
|
+
* const client = new VoiceAIClient({
|
|
15
|
+
* apiKey: 'vk_your_api_key'
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // List agents
|
|
19
|
+
* const agents = await client.agents.list();
|
|
20
|
+
*
|
|
21
|
+
* // Create and deploy an agent
|
|
22
|
+
* const agent = await client.agents.create({
|
|
23
|
+
* name: 'Support Agent',
|
|
24
|
+
* config: { prompt: 'You are a helpful assistant.' }
|
|
25
|
+
* });
|
|
26
|
+
* await client.agents.deploy(agent.agent_id);
|
|
27
|
+
*
|
|
28
|
+
* // Get call history
|
|
29
|
+
* const history = await client.analytics.getCallHistory();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
import { AgentClient } from './agents';
|
|
33
|
+
import { AnalyticsClient } from './analytics';
|
|
34
|
+
import { KnowledgeBaseClient } from './knowledge-base';
|
|
35
|
+
import { PhoneNumberClient } from './phone-numbers';
|
|
36
|
+
export { VoiceAIError } from './base';
|
|
37
|
+
/**
|
|
38
|
+
* Main API client for Voice.AI Agent API
|
|
39
|
+
*/
|
|
40
|
+
export class VoiceAIClient {
|
|
41
|
+
/**
|
|
42
|
+
* Create a new VoiceAIClient
|
|
43
|
+
*
|
|
44
|
+
* @param config - Client configuration
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const client = new VoiceAIClient({
|
|
49
|
+
* apiKey: 'vk_your_api_key',
|
|
50
|
+
* apiUrl: 'https://custom-api.example.com/api/v1' // optional
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
constructor(config) {
|
|
55
|
+
if (!config.apiKey) {
|
|
56
|
+
throw new Error('API key is required');
|
|
57
|
+
}
|
|
58
|
+
const apiUrl = config.apiUrl || VoiceAIClient.DEFAULT_API_URL;
|
|
59
|
+
const clientConfig = { apiKey: config.apiKey, apiUrl };
|
|
60
|
+
this.agents = new AgentClient(clientConfig);
|
|
61
|
+
this.analytics = new AnalyticsClient(clientConfig);
|
|
62
|
+
this.knowledgeBase = new KnowledgeBaseClient(clientConfig);
|
|
63
|
+
this.phoneNumbers = new PhoneNumberClient(clientConfig);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Default API URL */
|
|
67
|
+
VoiceAIClient.DEFAULT_API_URL = 'https://dev.voice.ai/api/v1';
|
|
68
|
+
// Re-export sub-clients for direct usage if needed
|
|
69
|
+
export { AgentClient } from './agents';
|
|
70
|
+
export { AnalyticsClient } from './analytics';
|
|
71
|
+
export { KnowledgeBaseClient } from './knowledge-base';
|
|
72
|
+
export { PhoneNumberClient } from './phone-numbers';
|
|
73
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC;;GAEG;AACH,MAAM,OAAO,aAAa;IAgBxB;;;;;;;;;;;;OAYG;IACH,YAAY,MAA2B;QACrC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACzC,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,aAAa,CAAC,eAAe,CAAC;QAC9D,MAAM,YAAY,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAEvD,IAAI,CAAC,MAAM,GAAG,IAAI,WAAW,CAAC,YAAY,CAAC,CAAC;QAC5C,IAAI,CAAC,SAAS,GAAG,IAAI,eAAe,CAAC,YAAY,CAAC,CAAC;QACnD,IAAI,CAAC,aAAa,GAAG,IAAI,mBAAmB,CAAC,YAAY,CAAC,CAAC;QAC3D,IA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