voicegate 0.1.0 → 0.1.1

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/package.json +2 -2
  2. package/src/index.js +43 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "voicegate",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
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/IgorSokhinov/voicegate-sdk.git"
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://api.aivoicegate.com').replace(/\/+$/, '');
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
- async _request(method, url, body, auth) {
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;
@@ -121,10 +125,43 @@ class VoiceGate {
121
125
  }
122
126
 
123
127
  // ── voice call (private beta) ──────────────────────────────────────────────
124
- async call({ to, agentWebhook, voice = 'female', language = 'en', initialMessage } = {}) {
125
- const body = { to, voice, language, agent_webhook: agentWebhook, pay: 'usdc:base' };
126
- if (initialMessage) body.initial_message = initialMessage;
127
- return this._request('POST', this.base + '/v1/agent-call', body, this.apiKey);
128
+ /**
129
+ * Place an outbound call.
130
+ *
131
+ * `greeting` is spoken the moment the line connects — say who is calling and
132
+ * on whose behalf. `prompt` drives the agent's side: goal, acceptable
133
+ * outcomes, when to hang up.
134
+ *
135
+ * Resolves to { status, call_uuid, hold_micros, rate_micros_per_min,
136
+ * destination_region }. The hold covers the maximum call length; you are
137
+ * charged for the billable seconds actually talked.
138
+ */
139
+ async call({ to, greeting, prompt, language = 'en', voice = 'female', agentId, callerId } = {}) {
140
+ const body = { to, greeting, prompt, language, voice };
141
+ if (agentId) body.agent_id = agentId;
142
+ if (callerId) body.caller_id = callerId;
143
+ return this._request('POST', this.base + '/v1/agent-call', body, null, this.apiKey);
144
+ }
145
+
146
+ // ── billing ────────────────────────────────────────────────────────────────
147
+ /** Balance, holds and the terms this account is charged under. */
148
+ async balance(agentId) {
149
+ return this._request('GET', `${this.base}/v1/billing/${agentId}/balance`, null, null, this.apiKey);
150
+ }
151
+
152
+ /**
153
+ * Bind a Base address so incoming USDC from it credits this agent. Link
154
+ * before sending anything: a transfer from an unknown address still arrives,
155
+ * but cannot be attributed to you automatically.
156
+ */
157
+ async linkWallet(agentId, walletAddress) {
158
+ return this._request('POST', `${this.base}/v1/billing/${agentId}/wallet`,
159
+ { wallet_address: walletAddress }, null, this.apiKey);
160
+ }
161
+
162
+ /** Append-only ledger: topup, hold, release, charge, refund, adjust. */
163
+ async transactions(agentId) {
164
+ return this._request('GET', `${this.base}/v1/billing/${agentId}/transactions`, null, null, this.apiKey);
128
165
  }
129
166
 
130
167
  // ── KYA — Know Your Agent (live) ───────────────────────────────────────────