voicegate 0.1.0 → 0.1.2
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/package.json +2 -2
- package/src/index.js +50 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "voicegate",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Node.js SDK for VoiceGate — voice infrastructure for AI agents, with KYA agent identity (by CallsFlow Ltd)",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"homepage": "https://aivoicegate.com",
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
25
|
-
"url": "https://github.com/
|
|
25
|
+
"url": "https://github.com/CallsFlow/voicegate-sdk.git"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|
|
28
28
|
"node": ">=18"
|
package/src/index.js
CHANGED
|
@@ -92,16 +92,20 @@ class VoiceGateError extends Error {
|
|
|
92
92
|
|
|
93
93
|
class VoiceGate {
|
|
94
94
|
constructor(opts = {}) {
|
|
95
|
-
this.base = (opts.baseUrl || 'https://
|
|
95
|
+
this.base = (opts.baseUrl || 'https://aivoicegate.com').replace(/\/+$/, '');
|
|
96
96
|
this.kya = (opts.kyaUrl || opts.baseUrl || this.base).replace(/\/+$/, '');
|
|
97
97
|
this.apiKey = opts.apiKey || null;
|
|
98
98
|
this.timeout = opts.timeout || 30000;
|
|
99
99
|
this._session = null;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
// `auth` is a KYA session token (Bearer); `apiKey` is the account key the
|
|
103
|
+
// gateway expects in x-api-key. Different headers — a key sent as Bearer
|
|
104
|
+
// just earns a 401.
|
|
105
|
+
async _request(method, url, body, auth, apiKey) {
|
|
103
106
|
const headers = { 'Content-Type': 'application/json' };
|
|
104
107
|
if (auth) headers['Authorization'] = 'Bearer ' + auth;
|
|
108
|
+
if (apiKey) headers['x-api-key'] = apiKey;
|
|
105
109
|
const ctrl = new AbortController();
|
|
106
110
|
const t = setTimeout(() => ctrl.abort(), this.timeout);
|
|
107
111
|
let resp;
|
|
@@ -120,11 +124,51 @@ class VoiceGate {
|
|
|
120
124
|
return text ? JSON.parse(text) : null;
|
|
121
125
|
}
|
|
122
126
|
|
|
127
|
+
// Чем представляться шлюзу. Сессия агента (вход по KYA-удостоверению) важнее
|
|
128
|
+
// ключа-интегратора: если агент вошёл сам, он и платит за свои звонки. Ключ
|
|
129
|
+
// от нас нужен только тем, кто ведёт много агентов из собственной системы.
|
|
130
|
+
_creds() {
|
|
131
|
+
return this._session ? [this._session, null] : [null, this.apiKey];
|
|
132
|
+
}
|
|
133
|
+
|
|
123
134
|
// ── voice call (private beta) ──────────────────────────────────────────────
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Place an outbound call.
|
|
137
|
+
*
|
|
138
|
+
* `greeting` is spoken the moment the line connects — say who is calling and
|
|
139
|
+
* on whose behalf. `prompt` drives the agent's side: goal, acceptable
|
|
140
|
+
* outcomes, when to hang up.
|
|
141
|
+
*
|
|
142
|
+
* Resolves to { status, call_uuid, hold_micros, rate_micros_per_min,
|
|
143
|
+
* destination_region }. The hold covers the maximum call length; you are
|
|
144
|
+
* charged for the billable seconds actually talked.
|
|
145
|
+
*/
|
|
146
|
+
async call({ to, greeting, prompt, language = 'en', voice = 'female', agentId, callerId } = {}) {
|
|
147
|
+
const body = { to, greeting, prompt, language, voice };
|
|
148
|
+
if (agentId) body.agent_id = agentId;
|
|
149
|
+
if (callerId) body.caller_id = callerId;
|
|
150
|
+
return this._request('POST', this.base + '/v1/agent-call', body, ...this._creds());
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ── billing ────────────────────────────────────────────────────────────────
|
|
154
|
+
/** Balance, holds and the terms this account is charged under. */
|
|
155
|
+
async balance(agentId) {
|
|
156
|
+
return this._request('GET', `${this.base}/v1/billing/${agentId}/balance`, null, ...this._creds());
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Bind a Base address so incoming USDC from it credits this agent. Link
|
|
161
|
+
* before sending anything: a transfer from an unknown address still arrives,
|
|
162
|
+
* but cannot be attributed to you automatically.
|
|
163
|
+
*/
|
|
164
|
+
async linkWallet(agentId, walletAddress) {
|
|
165
|
+
return this._request('POST', `${this.base}/v1/billing/${agentId}/wallet`,
|
|
166
|
+
{ wallet_address: walletAddress }, ...this._creds());
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Append-only ledger: topup, hold, release, charge, refund, adjust. */
|
|
170
|
+
async transactions(agentId) {
|
|
171
|
+
return this._request('GET', `${this.base}/v1/billing/${agentId}/transactions`, null, ...this._creds());
|
|
128
172
|
}
|
|
129
173
|
|
|
130
174
|
// ── KYA — Know Your Agent (live) ───────────────────────────────────────────
|