@dialgem/sdk 0.1.0-beta.0 → 0.1.0-beta.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/CHANGELOG.md +36 -0
- package/README.md +182 -23
- package/dist/index.cjs +735 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2256 -150
- package/dist/index.d.ts +2256 -150
- package/dist/index.js +732 -54
- package/dist/index.js.map +1 -1
- package/examples/export-calls.ts +11 -14
- package/examples/webhook-express.ts +22 -8
- package/examples/webhook-fastify.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -104,10 +104,10 @@ function isErrorBody(body) {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
// src/version.ts
|
|
107
|
-
var VERSION = "0.1.0-beta.
|
|
107
|
+
var VERSION = "0.1.0-beta.2";
|
|
108
108
|
|
|
109
109
|
// src/core/http.ts
|
|
110
|
-
var RETRYABLE_METHODS = /* @__PURE__ */ new Set(["GET", "PATCH", "DELETE"]);
|
|
110
|
+
var RETRYABLE_METHODS = /* @__PURE__ */ new Set(["GET", "PUT", "PATCH", "DELETE"]);
|
|
111
111
|
var MAX_RETRY_DELAY_MS = 6e4;
|
|
112
112
|
var HttpClient = class {
|
|
113
113
|
baseURL;
|
|
@@ -130,6 +130,19 @@ var HttpClient = class {
|
|
|
130
130
|
post(path2, body, options) {
|
|
131
131
|
return this.request("POST", path2, { body, options });
|
|
132
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* POST a `FormData` body — file uploads.
|
|
135
|
+
*
|
|
136
|
+
* The body is sent as-is and `Content-Type` is left unset, because only
|
|
137
|
+
* `fetch` knows the multipart boundary it is about to generate. Setting the
|
|
138
|
+
* header ourselves produces a request no server can parse.
|
|
139
|
+
*/
|
|
140
|
+
postForm(path2, form, options) {
|
|
141
|
+
return this.request("POST", path2, { body: form, options });
|
|
142
|
+
}
|
|
143
|
+
put(path2, body, options) {
|
|
144
|
+
return this.request("PUT", path2, { body, options });
|
|
145
|
+
}
|
|
133
146
|
patch(path2, body, options) {
|
|
134
147
|
return this.request("PATCH", path2, { body, options });
|
|
135
148
|
}
|
|
@@ -138,10 +151,11 @@ var HttpClient = class {
|
|
|
138
151
|
}
|
|
139
152
|
async request(method, path2, { query, body, options = {} }) {
|
|
140
153
|
const url = this.buildURL(path2, query);
|
|
141
|
-
const
|
|
142
|
-
const
|
|
154
|
+
const isForm = isFormData(body);
|
|
155
|
+
const headers = this.buildHeaders(body !== void 0 && !isForm, options.headers);
|
|
156
|
+
const payload = body === void 0 ? void 0 : isForm ? body : JSON.stringify(body);
|
|
143
157
|
const timeout = options.timeout ?? this.#timeout;
|
|
144
|
-
const maxRetries = options.maxRetries ?? (RETRYABLE_METHODS.has(method) ? this.#maxRetries : 0);
|
|
158
|
+
const maxRetries = isForm ? 0 : options.maxRetries ?? (RETRYABLE_METHODS.has(method) ? this.#maxRetries : 0);
|
|
145
159
|
assertTimeout(timeout);
|
|
146
160
|
assertMaxRetries(maxRetries);
|
|
147
161
|
for (let attempt = 0; ; attempt++) {
|
|
@@ -195,7 +209,7 @@ var HttpClient = class {
|
|
|
195
209
|
const params = new URLSearchParams();
|
|
196
210
|
for (const [key, value] of Object.entries(query)) {
|
|
197
211
|
if (value === void 0 || value === null) continue;
|
|
198
|
-
params.append(key, String(
|
|
212
|
+
for (const item of Array.isArray(value) ? value : [value]) params.append(key, String(item));
|
|
199
213
|
}
|
|
200
214
|
const qs = params.toString();
|
|
201
215
|
return qs ? `${url}?${qs}` : url;
|
|
@@ -218,6 +232,9 @@ var HttpClient = class {
|
|
|
218
232
|
return Object.fromEntries(merged.values());
|
|
219
233
|
}
|
|
220
234
|
};
|
|
235
|
+
function isFormData(value) {
|
|
236
|
+
return typeof FormData !== "undefined" && value instanceof FormData;
|
|
237
|
+
}
|
|
221
238
|
function assertTimeout(value) {
|
|
222
239
|
if (!Number.isInteger(value) || value <= 0) {
|
|
223
240
|
throw new DialgemError(`\`timeout\` must be a positive integer of milliseconds, got ${String(value)}.`);
|
|
@@ -314,11 +331,14 @@ var Agents = class extends APIResource {
|
|
|
314
331
|
knowledge;
|
|
315
332
|
/** Remote MCP servers whose tools are exposed to the agent. */
|
|
316
333
|
mcpServers;
|
|
334
|
+
/** Frozen snapshots of the agent that a number or a call can pin. */
|
|
335
|
+
versions;
|
|
317
336
|
constructor(client) {
|
|
318
337
|
super(client);
|
|
319
338
|
this.functions = new AgentFunctions(client);
|
|
320
339
|
this.knowledge = new AgentKnowledge(client);
|
|
321
340
|
this.mcpServers = new AgentMCPServers(client);
|
|
341
|
+
this.versions = new AgentVersions(client);
|
|
322
342
|
}
|
|
323
343
|
/** Create an agent. Only `name` is required; everything else has a server default. */
|
|
324
344
|
create(body, options) {
|
|
@@ -339,6 +359,48 @@ var Agents = class extends APIResource {
|
|
|
339
359
|
return this._client.delete(path`/v1/agents/${agentId}`, options);
|
|
340
360
|
}
|
|
341
361
|
};
|
|
362
|
+
var AgentVersions = class extends APIResource {
|
|
363
|
+
/** Freeze the agent as it is now. Returns the new version, snapshot included. */
|
|
364
|
+
publish(agentId, body = {}, options) {
|
|
365
|
+
return this._client.post(path`/v1/agents/${agentId}/versions`, body, options);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* One page of published versions, newest first, without their snapshots.
|
|
369
|
+
*
|
|
370
|
+
* Returns the array. When you need to page — an agent published on every
|
|
371
|
+
* deploy accumulates versions, and nothing prunes them — read `has_more` from
|
|
372
|
+
* {@link listPage} instead and pass the last `version` as `before_version`.
|
|
373
|
+
*/
|
|
374
|
+
async list(agentId, params, options) {
|
|
375
|
+
return (await this.listPage(agentId, params, options)).versions;
|
|
376
|
+
}
|
|
377
|
+
/** {@link list} with the `has_more` flag, for paging. */
|
|
378
|
+
listPage(agentId, params, options) {
|
|
379
|
+
return this._client.get(
|
|
380
|
+
path`/v1/agents/${agentId}/versions`,
|
|
381
|
+
// Spread into a plain query record: an `interface` has no index
|
|
382
|
+
// signature, so it does not structurally satisfy `Query`.
|
|
383
|
+
{ ...params },
|
|
384
|
+
options
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
/** One version with its full snapshot. Version 0 is the draft: use `agents.retrieve`. */
|
|
388
|
+
retrieve(agentId, version, options) {
|
|
389
|
+
return this._client.get(
|
|
390
|
+
path`/v1/agents/${agentId}/versions/${versionSegment(version)}`,
|
|
391
|
+
void 0,
|
|
392
|
+
options
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
function versionSegment(version) {
|
|
397
|
+
if (!Number.isInteger(version) || version < 1) {
|
|
398
|
+
throw new DialgemError(
|
|
399
|
+
`Expected a published version number (a positive integer), got ${JSON.stringify(version)}. Version 0 is the draft \u2014 read it with agents.retrieve().`
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
return String(version);
|
|
403
|
+
}
|
|
342
404
|
var AgentFunctions = class extends APIResource {
|
|
343
405
|
list(agentId, options) {
|
|
344
406
|
return this._client.get(path`/v1/agents/${agentId}/functions`, void 0, options);
|
|
@@ -383,6 +445,13 @@ var AgentMCPServers = class extends APIResource {
|
|
|
383
445
|
return this._client.delete(path`/v1/agents/${agentId}/mcp-servers/${serverId}`, options);
|
|
384
446
|
}
|
|
385
447
|
/** Connect to the server now, list its tools, and store the result as `last_status`. */
|
|
448
|
+
/**
|
|
449
|
+
* What the server offers right now, with each tool's description and argument schema. Connects live like
|
|
450
|
+
* `test`, but stores nothing. An unreachable server is not an error: `tools` is empty and `error` says why.
|
|
451
|
+
*/
|
|
452
|
+
listTools(agentId, serverId, options) {
|
|
453
|
+
return this._client.get(path`/v1/agents/${agentId}/mcp-servers/${serverId}/tools`, void 0, options);
|
|
454
|
+
}
|
|
386
455
|
test(agentId, serverId, options) {
|
|
387
456
|
return this._client.post(path`/v1/agents/${agentId}/mcp-servers/${serverId}/test`, void 0, options);
|
|
388
457
|
}
|
|
@@ -391,35 +460,33 @@ var AgentMCPServers = class extends APIResource {
|
|
|
391
460
|
// src/core/pagination.ts
|
|
392
461
|
var Page = class _Page {
|
|
393
462
|
data;
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
page_size;
|
|
463
|
+
has_more;
|
|
464
|
+
pagination_key;
|
|
397
465
|
#fetchPage;
|
|
398
466
|
constructor(data, fetchPage) {
|
|
399
467
|
this.data = data.data;
|
|
400
|
-
this.
|
|
401
|
-
this.
|
|
402
|
-
this.page_size = data.page_size;
|
|
468
|
+
this.has_more = data.has_more;
|
|
469
|
+
this.pagination_key = data.pagination_key;
|
|
403
470
|
this.#fetchPage = fetchPage;
|
|
404
471
|
}
|
|
405
472
|
hasNextPage() {
|
|
406
|
-
return this.
|
|
473
|
+
return this.has_more && this.pagination_key !== null;
|
|
407
474
|
}
|
|
408
475
|
async getNextPage() {
|
|
409
476
|
if (!this.hasNextPage()) throw new DialgemError("No next page; check hasNextPage() first.");
|
|
410
|
-
return new _Page(await this.#fetchPage(this.
|
|
477
|
+
return new _Page(await this.#fetchPage(this.pagination_key), this.#fetchPage);
|
|
411
478
|
}
|
|
412
479
|
};
|
|
413
480
|
var PagePromise = class {
|
|
414
481
|
#fetchPage;
|
|
415
|
-
#
|
|
482
|
+
#startKey;
|
|
416
483
|
#first;
|
|
417
|
-
constructor(fetchPage,
|
|
484
|
+
constructor(fetchPage, startKey = null) {
|
|
418
485
|
this.#fetchPage = fetchPage;
|
|
419
|
-
this.#
|
|
486
|
+
this.#startKey = startKey;
|
|
420
487
|
}
|
|
421
488
|
#firstPage() {
|
|
422
|
-
this.#first ??= this.#fetchPage(this.#
|
|
489
|
+
this.#first ??= this.#fetchPage(this.#startKey).then((data) => new Page(data, this.#fetchPage));
|
|
423
490
|
return this.#first;
|
|
424
491
|
}
|
|
425
492
|
then(onfulfilled, onrejected) {
|
|
@@ -444,24 +511,64 @@ var PagePromise = class {
|
|
|
444
511
|
// src/resources/calls.ts
|
|
445
512
|
var Calls = class extends APIResource {
|
|
446
513
|
/**
|
|
447
|
-
* Calls, newest first. Await for one page, or iterate for every call:
|
|
514
|
+
* Calls, newest first by default. Await for one page, or iterate for every call:
|
|
448
515
|
*
|
|
449
|
-
* const page = await dialgem.calls.list({
|
|
450
|
-
* for await (const call of dialgem.calls.list({ status: "completed" })) {
|
|
451
|
-
* if (call.started_at < cutoff) break // newest first: everything after is older
|
|
452
|
-
* }
|
|
516
|
+
* const page = await dialgem.calls.list({ limit: 50 })
|
|
517
|
+
* for await (const call of dialgem.calls.list({ status: "completed", start_after: since })) { ... }
|
|
453
518
|
*/
|
|
454
519
|
list(params = {}, options) {
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
|
|
520
|
+
const query = toQuery(params);
|
|
521
|
+
const fetchPage = async (paginationKey) => {
|
|
522
|
+
const res = await this._client.get(
|
|
523
|
+
"/v1/calls",
|
|
524
|
+
{ ...query, pagination_key: paginationKey ?? void 0 },
|
|
525
|
+
options
|
|
526
|
+
);
|
|
527
|
+
return { data: res.calls, has_more: res.has_more, pagination_key: res.pagination_key };
|
|
458
528
|
};
|
|
459
|
-
return new PagePromise(fetchPage
|
|
529
|
+
return new PagePromise(fetchPage);
|
|
460
530
|
}
|
|
461
|
-
/** One call, including its transcript, analysis and recording URL. */
|
|
531
|
+
/** One call, including its transcript, analysis, latency and recording URL. */
|
|
462
532
|
retrieve(callId, options) {
|
|
463
533
|
return this._client.get(path`/v1/calls/${callId}`, void 0, options);
|
|
464
534
|
}
|
|
535
|
+
/** Replace the call's `metadata`. */
|
|
536
|
+
update(callId, body, options) {
|
|
537
|
+
return this._client.patch(path`/v1/calls/${callId}`, body, options);
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Permanently delete a finished call: its record, transcript, analysis and
|
|
541
|
+
* recording. A call still in progress is refused with `ConflictError`; stop it first.
|
|
542
|
+
*/
|
|
543
|
+
delete(callId, options) {
|
|
544
|
+
return this._client.delete(path`/v1/calls/${callId}`, options);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Run a finished call's post-call analysis again, with the agent's *current* analysis
|
|
548
|
+
* settings, and return the updated call. Use it after changing the fields or the model
|
|
549
|
+
* and wanting an older call read the new way.
|
|
550
|
+
*
|
|
551
|
+
* It replaces `analysis`; it does not bill the call again and does not send `call_analyzed`
|
|
552
|
+
* again, so read the result from this response or from `retrieve`. The model call can take
|
|
553
|
+
* a while. `ConflictError` with `errCode` `call_in_progress` until the call has ended,
|
|
554
|
+
* `no_transcript` when there is nothing to analyze, `agent_deleted` if the agent is gone.
|
|
555
|
+
* Not retried by default.
|
|
556
|
+
*/
|
|
557
|
+
rerunAnalysis(callId, options) {
|
|
558
|
+
return this._client.post(path`/v1/calls/${callId}/rerun-analysis`, void 0, options);
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* End an ongoing call now, as if the agent had hung up. The call becomes
|
|
562
|
+
* `completed` with `disconnection_reason: "manual_stopped"` a moment later, and
|
|
563
|
+
* the usual `call_ended` webhook follows.
|
|
564
|
+
*
|
|
565
|
+
* `ConflictError` with `errCode` `call_not_ongoing` if it already ended, or
|
|
566
|
+
* `call_not_connected` if no agent is on the call yet (e.g. still ringing).
|
|
567
|
+
* Not retried by default.
|
|
568
|
+
*/
|
|
569
|
+
stop(callId, options) {
|
|
570
|
+
return this._client.post(path`/v1/calls/${callId}/stop`, void 0, options);
|
|
571
|
+
}
|
|
465
572
|
/**
|
|
466
573
|
* Dial `to` from one of your organization's numbers, with `agent_id` (or the
|
|
467
574
|
* number's outbound agent) on the line.
|
|
@@ -481,13 +588,76 @@ var Calls = class extends APIResource {
|
|
|
481
588
|
return this._client.post("/v1/calls/register", body, options);
|
|
482
589
|
}
|
|
483
590
|
};
|
|
591
|
+
function toQuery(params) {
|
|
592
|
+
const { metadata, ...rest } = params;
|
|
593
|
+
const query = { ...rest };
|
|
594
|
+
query["limit"] = params.limit ?? 10;
|
|
595
|
+
for (const [key, value] of Object.entries(metadata ?? {})) {
|
|
596
|
+
query[`metadata.${key}`] = String(value);
|
|
597
|
+
}
|
|
598
|
+
return query;
|
|
599
|
+
}
|
|
484
600
|
|
|
485
601
|
// src/resources/catalog.ts
|
|
486
602
|
var Voices = class extends APIResource {
|
|
487
|
-
/**
|
|
603
|
+
/**
|
|
604
|
+
* Voices available to agents: the shared catalog plus the ones your
|
|
605
|
+
* organization cloned, yours first. Put a voice's `provider_voice_id` in an
|
|
606
|
+
* agent's `voice_id`.
|
|
607
|
+
*/
|
|
488
608
|
list(params = {}, options) {
|
|
489
609
|
return this._client.get("/v1/voices", params, options);
|
|
490
610
|
}
|
|
611
|
+
/**
|
|
612
|
+
* Clone a voice from audio you upload. The new voice is private to your
|
|
613
|
+
* organization and never appears in another one's catalog.
|
|
614
|
+
*
|
|
615
|
+
* Consent is required: you are asserting that you hold the rights to the
|
|
616
|
+
* audio and have the speaker's consent, and that assertion is recorded
|
|
617
|
+
* against your API identity.
|
|
618
|
+
*
|
|
619
|
+
* The upload is never retried, whatever `maxRetries` says — a retried
|
|
620
|
+
* multipart body can send truncated audio, and a clone built from half the
|
|
621
|
+
* recording succeeds and sounds wrong.
|
|
622
|
+
*/
|
|
623
|
+
clone(params, options) {
|
|
624
|
+
const { name, files, consent_confirmed, engine, description, language, filenames } = params;
|
|
625
|
+
if (!consent_confirmed) {
|
|
626
|
+
throw new DialgemError(
|
|
627
|
+
"consent_confirmed must be true: you are asserting that you hold the rights to this audio and have the speaker's consent to clone their voice."
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
if (!files?.length) {
|
|
631
|
+
throw new DialgemError("At least one audio file is required to clone a voice.");
|
|
632
|
+
}
|
|
633
|
+
const form = new FormData();
|
|
634
|
+
form.append("name", name);
|
|
635
|
+
form.append("consent_confirmed", "true");
|
|
636
|
+
if (engine) form.append("engine", engine);
|
|
637
|
+
if (description) form.append("description", description);
|
|
638
|
+
if (language) form.append("language", language);
|
|
639
|
+
files.forEach((file, i) => {
|
|
640
|
+
const fallback = file.name || `clip-${i + 1}.wav`;
|
|
641
|
+
form.append("files", file, filenames?.[i] ?? fallback);
|
|
642
|
+
});
|
|
643
|
+
return this._client.postForm("/v1/voices/clone", form, options);
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Delete a voice your organization cloned, at the provider and here.
|
|
647
|
+
*
|
|
648
|
+
* Only your own cloned voices: the shared catalog is not deletable, and a
|
|
649
|
+
* voice an agent still uses is refused with a 409 rather than leaving that
|
|
650
|
+
* agent without one.
|
|
651
|
+
*/
|
|
652
|
+
delete(voiceId, options) {
|
|
653
|
+
return this._client.delete(path`/v1/voices/${voiceId}`, options);
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
var ExtractionModels = class extends APIResource {
|
|
657
|
+
/** Models an agent may use for post-call analysis, with an estimated cost per session. */
|
|
658
|
+
list(options) {
|
|
659
|
+
return this._client.get("/v1/models/extraction", void 0, options);
|
|
660
|
+
}
|
|
491
661
|
};
|
|
492
662
|
var FlowTemplates = class extends APIResource {
|
|
493
663
|
/** Built-in conversation-flow templates (summaries, without `flow_config`). */
|
|
@@ -508,6 +678,287 @@ var PromptTemplates = class extends APIResource {
|
|
|
508
678
|
}
|
|
509
679
|
};
|
|
510
680
|
|
|
681
|
+
// src/resources/account.ts
|
|
682
|
+
var ApiKey = class extends APIResource {
|
|
683
|
+
/**
|
|
684
|
+
* Who this key is: your organization and the key's name, prefix, scopes, allowed addresses
|
|
685
|
+
* and expiry. It answers for any valid key whatever its scopes, so an integration can check
|
|
686
|
+
* what it was given. Never returns the secret.
|
|
687
|
+
*
|
|
688
|
+
* ```ts
|
|
689
|
+
* const { key } = await dialgem.apiKey.retrieve()
|
|
690
|
+
* if (key && !key.full_access) console.log("scoped to", key.scopes)
|
|
691
|
+
* ```
|
|
692
|
+
*/
|
|
693
|
+
retrieve(options) {
|
|
694
|
+
return this._client.get("/v1/api-key-info", void 0, options);
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
var Sessions = class extends APIResource {
|
|
698
|
+
/**
|
|
699
|
+
* The calls your organization has in progress right now, with a `count`.
|
|
700
|
+
*
|
|
701
|
+
* Live state read from the service's own registry — use it for a
|
|
702
|
+
* concurrency check before placing a call. For finished calls use
|
|
703
|
+
* `calls.list`; a call whose teardown never arrived is not counted here.
|
|
704
|
+
*/
|
|
705
|
+
list(options) {
|
|
706
|
+
return this._client.get("/v1/agent/sessions", void 0, options);
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Change a live call's prompt and/or variables. It applies from the agent's **next turn**.
|
|
710
|
+
*
|
|
711
|
+
* `sessionId` is a session's `session_id` from `list`, or the call's own `call_id`. Only this call changes:
|
|
712
|
+
* the agent, its published versions and other calls are untouched, and the change is gone when the call ends.
|
|
713
|
+
* A turn already being spoken finishes as it was. `dynamic_variables` are merged over the call's variables;
|
|
714
|
+
* `system_prompt` replaces the prompt for the rest of the call.
|
|
715
|
+
*
|
|
716
|
+
* The call may be on any service instance. `NotFoundError` if it is not live (or is another organization's),
|
|
717
|
+
* `ConflictError` with `errCode` `session_ended` once it is over, `UnprocessableEntityError` with `errCode`
|
|
718
|
+
* `flow_agent_prompt` for a flow agent's prompt (its variables can still change). Not retried by default.
|
|
719
|
+
*
|
|
720
|
+
* ```ts
|
|
721
|
+
* await dialgem.sessions.update(callId, { dynamic_variables: { plan: "pro" } })
|
|
722
|
+
* ```
|
|
723
|
+
*/
|
|
724
|
+
update(sessionId, body, options) {
|
|
725
|
+
return this._client.patch(path`/v1/agent/sessions/${sessionId}`, body, options);
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Make the agent say `text` on a live call, in its own voice. Answers at once; the line plays behind what the
|
|
729
|
+
* agent is saying, or now with `interrupt: true`. The agent's conversation records it as something it said.
|
|
730
|
+
*
|
|
731
|
+
* Off unless the deployment enables live control: `ForbiddenError` with `errCode` `live_control_disabled`.
|
|
732
|
+
* `ConflictError` `human_has_call` while a human has taken the call. Owners, admins and API keys only.
|
|
733
|
+
* Not retried by default.
|
|
734
|
+
*
|
|
735
|
+
* ```ts
|
|
736
|
+
* await dialgem.sessions.say(callId, { text: "One moment while I check that." })
|
|
737
|
+
* ```
|
|
738
|
+
*/
|
|
739
|
+
say(sessionId, body, options) {
|
|
740
|
+
return this._client.post(path`/v1/agent/sessions/${sessionId}/say`, body, options);
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Hand a taken-over call back to the agent, for when the socket that took it is gone. The agent is told a
|
|
744
|
+
* human had the call and that it did not hear what was said. Same availability and limits as `say`.
|
|
745
|
+
* Listening in and taking over run over a WebSocket (`/v1/agent/sessions/{id}/live`), which this SDK does not wrap.
|
|
746
|
+
*/
|
|
747
|
+
release(sessionId, options) {
|
|
748
|
+
return this._client.post(path`/v1/agent/sessions/${sessionId}/release`, void 0, options);
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
// src/resources/simulations.ts
|
|
753
|
+
var Simulations = class extends APIResource {
|
|
754
|
+
/** Make a suite for one of your agents. */
|
|
755
|
+
createSuite(body, options) {
|
|
756
|
+
return this._client.post("/v1/simulations/suites", body, options);
|
|
757
|
+
}
|
|
758
|
+
/** Your suites, newest first, each with its latest run. Pass `agent_id` for one agent's. */
|
|
759
|
+
listSuites(params = {}, options) {
|
|
760
|
+
return this._client.get("/v1/simulations/suites", params, options);
|
|
761
|
+
}
|
|
762
|
+
/** One suite with its cases. */
|
|
763
|
+
retrieveSuite(suiteId, options) {
|
|
764
|
+
return this._client.get(path`/v1/simulations/suites/${suiteId}`, void 0, options);
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Rename a suite or set its publish gate: `off`, `warn` (publishing a version succeeds and lists the suites the draft
|
|
768
|
+
* has not passed) or `block` (publishing is refused with 409 `simulation_required` until it has).
|
|
769
|
+
*/
|
|
770
|
+
updateSuite(suiteId, body, options) {
|
|
771
|
+
return this._client.patch(path`/v1/simulations/suites/${suiteId}`, body, options);
|
|
772
|
+
}
|
|
773
|
+
/** Delete a suite and its cases. Past runs are deleted with it. */
|
|
774
|
+
deleteSuite(suiteId, options) {
|
|
775
|
+
return this._client.delete(path`/v1/simulations/suites/${suiteId}`, options);
|
|
776
|
+
}
|
|
777
|
+
/** Add a case (up to 50 per suite). 422 `invalid_case` says what to fix. */
|
|
778
|
+
createCase(suiteId, body, options) {
|
|
779
|
+
return this._client.post(path`/v1/simulations/suites/${suiteId}/cases`, body, options);
|
|
780
|
+
}
|
|
781
|
+
/** Change a case. Fields you leave out keep their value. */
|
|
782
|
+
updateCase(caseId, body, options) {
|
|
783
|
+
return this._client.patch(path`/v1/simulations/cases/${caseId}`, body, options);
|
|
784
|
+
}
|
|
785
|
+
deleteCase(caseId, options) {
|
|
786
|
+
return this._client.delete(path`/v1/simulations/cases/${caseId}`, options);
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Run every case of a suite against the draft, a published version or `"latest_published"`. Answers at once
|
|
790
|
+
* (`202`); the run happens in the background, so poll `retrieveRun` until `status` is `completed`.
|
|
791
|
+
*
|
|
792
|
+
* 409 `suite_empty`, 422 `agent_type_not_supported` (multi-prompt agents), 429 `too_many_runs` or
|
|
793
|
+
* `daily_run_limit`.
|
|
794
|
+
*/
|
|
795
|
+
run(suiteId, body = {}, options) {
|
|
796
|
+
return this._client.post(path`/v1/simulations/suites/${suiteId}/runs`, body, options);
|
|
797
|
+
}
|
|
798
|
+
/** Runs, newest first. Pass `suite_id` for one suite's. */
|
|
799
|
+
listRuns(params = {}, options) {
|
|
800
|
+
return this._client.get("/v1/simulations/runs", params, options);
|
|
801
|
+
}
|
|
802
|
+
/** A run with every case's transcript, tool calls and check results. */
|
|
803
|
+
retrieveRun(runId, options) {
|
|
804
|
+
return this._client.get(path`/v1/simulations/runs/${runId}`, void 0, options);
|
|
805
|
+
}
|
|
806
|
+
/** Stop a run that has not finished. Cases already under way finish; the rest are skipped. */
|
|
807
|
+
cancelRun(runId, options) {
|
|
808
|
+
return this._client.post(path`/v1/simulations/runs/${runId}/cancel`, void 0, options);
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
|
|
812
|
+
// src/resources/web-calls.ts
|
|
813
|
+
var WebCalls = class extends APIResource {
|
|
814
|
+
/**
|
|
815
|
+
* Create a call for one visitor and get its access token.
|
|
816
|
+
*
|
|
817
|
+
* const { access_token } = await dialgem.webCalls.create({ agent_id, metadata: { visitor: "v_123" } })
|
|
818
|
+
*
|
|
819
|
+
* `metadata` and `dialgem_llm_dynamic_variables` are fixed here, by you, and cannot be changed by the page.
|
|
820
|
+
* 409 `web_origins_not_configured` until an origin is allowed; 402 if the organization cannot pay for calls;
|
|
821
|
+
* 429 when more than `limits.tokens_per_minute` calls are created in a minute.
|
|
822
|
+
*/
|
|
823
|
+
create(body, options) {
|
|
824
|
+
return this._client.post("/v1/calls/web", body, options);
|
|
825
|
+
}
|
|
826
|
+
/** The origins browser calls may start from, and the limits that apply. */
|
|
827
|
+
retrieveSettings(options) {
|
|
828
|
+
return this._client.get("/v1/web-calls/settings", void 0, options);
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Replace the allowed origins. Each is `scheme://host[:port]`; `https://*.example.com` allows any subdomain
|
|
832
|
+
* (not the bare domain) and `*` allows any website. Tokens already issued keep the list they were issued with.
|
|
833
|
+
*/
|
|
834
|
+
updateSettings(body, options) {
|
|
835
|
+
return this._client.put("/v1/web-calls/settings", body, options);
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
// src/resources/contacts.ts
|
|
840
|
+
var Contacts = class extends APIResource {
|
|
841
|
+
/** Bulk import from CSV, with a dry-run preview. */
|
|
842
|
+
imports;
|
|
843
|
+
constructor(client) {
|
|
844
|
+
super(client);
|
|
845
|
+
this.imports = new ContactImports(client);
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* Add a contact. `phone` is any way of writing a valid number; without a leading `+`
|
|
849
|
+
* also pass `default_country` (`"US"`). A number that is already a contact answers 409
|
|
850
|
+
* with its `contact_id`.
|
|
851
|
+
*/
|
|
852
|
+
create(body, options) {
|
|
853
|
+
return this._client.post("/v1/contacts", body, options);
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Contacts, newest first. Await for one page, or iterate for every contact:
|
|
857
|
+
*
|
|
858
|
+
*/
|
|
859
|
+
list(params = {}, options) {
|
|
860
|
+
const fetchPage = async (cursor) => {
|
|
861
|
+
const res = await this._client.get(
|
|
862
|
+
"/v1/contacts",
|
|
863
|
+
{ ...params, cursor: cursor ?? void 0 },
|
|
864
|
+
options
|
|
865
|
+
);
|
|
866
|
+
return { data: res.contacts, has_more: res.next_cursor !== null, pagination_key: res.next_cursor };
|
|
867
|
+
};
|
|
868
|
+
return new PagePromise(fetchPage);
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* The contact with this phone number. The number is matched as E.164, so
|
|
872
|
+
* `("(212) 220-0001", { default_country: "US" })` finds `+12122200001`. Throws
|
|
873
|
+
* `NotFoundError` if you have no such contact, and `UnprocessableEntityError` if the text is
|
|
874
|
+
* not a phone number.
|
|
875
|
+
*/
|
|
876
|
+
retrieveByPhone(phone, params = {}, options) {
|
|
877
|
+
return this._client.get(path`/v1/contacts/by-phone/${phone}`, params, options);
|
|
878
|
+
}
|
|
879
|
+
/** One contact, with its lists and how many calls it has had. */
|
|
880
|
+
retrieve(contactId, options) {
|
|
881
|
+
return this._client.get(path`/v1/contacts/${contactId}`, void 0, options);
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Partial update: only the fields you send change, and `null` clears a field.
|
|
885
|
+
* `attributes` replaces the whole set, so send every field you want kept.
|
|
886
|
+
*/
|
|
887
|
+
update(contactId, body, options) {
|
|
888
|
+
return this._client.patch(path`/v1/contacts/${contactId}`, body, options);
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Erase a contact and its list memberships. Calls already made stay in the call log, and
|
|
892
|
+
* a do-not-call entry for the number stays too, so forgetting a person never makes a number
|
|
893
|
+
* that asked not to be called dialable again.
|
|
894
|
+
*/
|
|
895
|
+
delete(contactId, options) {
|
|
896
|
+
return this._client.delete(path`/v1/contacts/${contactId}`, options);
|
|
897
|
+
}
|
|
898
|
+
/** Calls to or from the contact's number, newest first. Summaries, not transcripts. */
|
|
899
|
+
calls(contactId, params = {}, options) {
|
|
900
|
+
return this._client.get(path`/v1/contacts/${contactId}/calls`, params, options);
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
var ContactImports = class extends APIResource {
|
|
904
|
+
/** The file's headers, a guessed column mapping and a few rows. Imports nothing. */
|
|
905
|
+
inspect(csv, options) {
|
|
906
|
+
return this._client.post("/v1/contacts/imports/inspect", { csv }, options);
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* Start an import. Without `mapping` the columns are guessed from the headers. With
|
|
910
|
+
* `dry_run: true` nothing is written: the import only validates and reports.
|
|
911
|
+
*/
|
|
912
|
+
create(body, options) {
|
|
913
|
+
return this._client.post("/v1/contacts/imports", body, options);
|
|
914
|
+
}
|
|
915
|
+
/** Recent imports, newest first. */
|
|
916
|
+
list(options) {
|
|
917
|
+
return this._client.get("/v1/contacts/imports", void 0, options);
|
|
918
|
+
}
|
|
919
|
+
/** Progress and counts. */
|
|
920
|
+
retrieve(importId, options) {
|
|
921
|
+
return this._client.get(path`/v1/contacts/imports/${importId}`, void 0, options);
|
|
922
|
+
}
|
|
923
|
+
/** The rows that were rejected, with the line, the reason and what each held. */
|
|
924
|
+
errors(importId, params = {}, options) {
|
|
925
|
+
return this._client.get(path`/v1/contacts/imports/${importId}/errors`, params, options);
|
|
926
|
+
}
|
|
927
|
+
/** Apply a previewed import: the file is read again, so what is applied is what was previewed. */
|
|
928
|
+
commit(importId, options) {
|
|
929
|
+
return this._client.post(path`/v1/contacts/imports/${importId}/commit`, void 0, options);
|
|
930
|
+
}
|
|
931
|
+
/** Stop an import that has not finished. Contacts a running import already wrote stay. */
|
|
932
|
+
cancel(importId, options) {
|
|
933
|
+
return this._client.delete(path`/v1/contacts/imports/${importId}`, options);
|
|
934
|
+
}
|
|
935
|
+
};
|
|
936
|
+
var ContactLists = class extends APIResource {
|
|
937
|
+
list(options) {
|
|
938
|
+
return this._client.get("/v1/contact-lists", void 0, options);
|
|
939
|
+
}
|
|
940
|
+
/** Names are unique within your organization, ignoring case. */
|
|
941
|
+
create(body, options) {
|
|
942
|
+
return this._client.post("/v1/contact-lists", body, options);
|
|
943
|
+
}
|
|
944
|
+
retrieve(listId, options) {
|
|
945
|
+
return this._client.get(path`/v1/contact-lists/${listId}`, void 0, options);
|
|
946
|
+
}
|
|
947
|
+
update(listId, body, options) {
|
|
948
|
+
return this._client.patch(path`/v1/contact-lists/${listId}`, body, options);
|
|
949
|
+
}
|
|
950
|
+
delete(listId, options) {
|
|
951
|
+
return this._client.delete(path`/v1/contact-lists/${listId}`, options);
|
|
952
|
+
}
|
|
953
|
+
/** Add up to 1000 of your contacts. Already-members are ignored; `added` says how many were new. */
|
|
954
|
+
addContacts(listId, contactIds, options) {
|
|
955
|
+
return this._client.post(path`/v1/contact-lists/${listId}/members`, { contact_ids: contactIds }, options);
|
|
956
|
+
}
|
|
957
|
+
removeContact(listId, contactId, options) {
|
|
958
|
+
return this._client.delete(path`/v1/contact-lists/${listId}/members/${contactId}`, options);
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
|
|
511
962
|
// src/resources/phone-numbers.ts
|
|
512
963
|
var PhoneNumbers = class extends APIResource {
|
|
513
964
|
/** Register a number you own (`phone_number` in E.164) with Dialgem. */
|
|
@@ -518,6 +969,20 @@ var PhoneNumbers = class extends APIResource {
|
|
|
518
969
|
list(options) {
|
|
519
970
|
return this._client.get("/v1/phone-numbers", void 0, options);
|
|
520
971
|
}
|
|
972
|
+
/**
|
|
973
|
+
* One number by its E.164 value, e.g. `+14155550123`.
|
|
974
|
+
*
|
|
975
|
+
* Keyed on the number rather than on `id`, because the number is what you
|
|
976
|
+
* have when you are asking whether it is registered at all. Throws
|
|
977
|
+
* `NotFoundError` when it is not.
|
|
978
|
+
*/
|
|
979
|
+
retrieve(phoneNumber, options) {
|
|
980
|
+
return this._client.get(
|
|
981
|
+
path`/v1/phone-numbers/by-number/${phoneNumber}`,
|
|
982
|
+
void 0,
|
|
983
|
+
options
|
|
984
|
+
);
|
|
985
|
+
}
|
|
521
986
|
/**
|
|
522
987
|
* Partial update.
|
|
523
988
|
*
|
|
@@ -533,61 +998,237 @@ var PhoneNumbers = class extends APIResource {
|
|
|
533
998
|
assign(phoneNumberId, body, options) {
|
|
534
999
|
return this._client.patch(path`/v1/phone-numbers/${phoneNumberId}/assign`, body, options);
|
|
535
1000
|
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Send one signed test request to the number's inbound routing webhook and report what a real call would have done
|
|
1003
|
+
* with your answer: the status, how long you took against the time budget, and any field that would be ignored.
|
|
1004
|
+
* Throws a `ConflictError` (`inbound_webhook_not_set`) when the number has no `inbound_webhook_url`.
|
|
1005
|
+
*/
|
|
1006
|
+
testInboundWebhook(phoneNumberId, options) {
|
|
1007
|
+
return this._client.post(path`/v1/phone-numbers/${phoneNumberId}/inbound-webhook/test`, void 0, options);
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Replace the inbound webhook's signing secret. The new secret is returned **once**, as `inbound_webhook_secret`
|
|
1011
|
+
* on the number; the old one stops working at once.
|
|
1012
|
+
*/
|
|
1013
|
+
rotateInboundWebhookSecret(phoneNumberId, options) {
|
|
1014
|
+
return this._client.post(path`/v1/phone-numbers/${phoneNumberId}/inbound-webhook/rotate-secret`, void 0, options);
|
|
1015
|
+
}
|
|
536
1016
|
/** Release the number from Dialgem. It stops routing calls and disappears from `list()`; your carrier account is untouched. */
|
|
537
1017
|
delete(phoneNumberId, options) {
|
|
538
1018
|
return this._client.delete(path`/v1/phone-numbers/${phoneNumberId}`, options);
|
|
539
1019
|
}
|
|
540
1020
|
};
|
|
541
1021
|
|
|
1022
|
+
// src/resources/chats.ts
|
|
1023
|
+
var Chats = class extends APIResource {
|
|
1024
|
+
/**
|
|
1025
|
+
* Start a chat. If the agent has a first message it is already in `messages`.
|
|
1026
|
+
*
|
|
1027
|
+
* `UnprocessableEntityError` with `errCode` `agent_type_not_supported` (flow agents) or `chat_requires_storage`.
|
|
1028
|
+
* Not retried by default.
|
|
1029
|
+
*/
|
|
1030
|
+
create(body, options) {
|
|
1031
|
+
return this._client.post("/v1/chats", body, options);
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* Chats, newest first. Await for one page, or iterate for every chat. Entries leave out `messages`;
|
|
1035
|
+
* `retrieve` a chat for them.
|
|
1036
|
+
*/
|
|
1037
|
+
list(params = {}, options) {
|
|
1038
|
+
const fetchPage = async (paginationKey) => {
|
|
1039
|
+
const res = await this._client.get(
|
|
1040
|
+
"/v1/chats",
|
|
1041
|
+
{ ...params, pagination_key: paginationKey ?? void 0 },
|
|
1042
|
+
options
|
|
1043
|
+
);
|
|
1044
|
+
return { data: res.chats, has_more: res.has_more, pagination_key: res.pagination_key };
|
|
1045
|
+
};
|
|
1046
|
+
return new PagePromise(fetchPage);
|
|
1047
|
+
}
|
|
1048
|
+
/** One chat with all its messages. */
|
|
1049
|
+
retrieve(chatId, options) {
|
|
1050
|
+
return this._client.get(path`/v1/chats/${chatId}`, void 0, options);
|
|
1051
|
+
}
|
|
1052
|
+
/** Replace the chat's `metadata` (the whole object). */
|
|
1053
|
+
update(chatId, body, options) {
|
|
1054
|
+
return this._client.patch(path`/v1/chats/${chatId}`, body, options);
|
|
1055
|
+
}
|
|
1056
|
+
/** Delete a chat and its messages. */
|
|
1057
|
+
delete(chatId, options) {
|
|
1058
|
+
return this._client.delete(path`/v1/chats/${chatId}`, options);
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Send the user's message and wait for the agent's reply. Returns only the new entries, in order: the user's
|
|
1062
|
+
* message, any tool use, the agent's reply.
|
|
1063
|
+
*
|
|
1064
|
+
* If the agent's model fails (`ServerError`, `errCode` `model_error`) nothing is stored and the same message
|
|
1065
|
+
* can be sent again. `ConflictError` with `errCode` `chat_busy` while another reply is in progress,
|
|
1066
|
+
* `chat_ended` after the end, `message_limit` at the cap. If the agent calls its end-call tool, the reply's
|
|
1067
|
+
* `chat_status` is `ended`.
|
|
1068
|
+
*
|
|
1069
|
+
* Not retried by default: a retry after an ambiguous failure could send the message twice.
|
|
1070
|
+
*/
|
|
1071
|
+
sendMessage(chatId, content, options) {
|
|
1072
|
+
return this._client.post(path`/v1/chats/${chatId}/messages`, { content }, options);
|
|
1073
|
+
}
|
|
1074
|
+
/** End the chat. Ending twice is fine. The analysis arrives a moment later; read it with `retrieve`. */
|
|
1075
|
+
end(chatId, options) {
|
|
1076
|
+
return this._client.post(path`/v1/chats/${chatId}/end`, void 0, options);
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Analyse an ended chat again with the agent's current analysis settings and return it. `ConflictError` with
|
|
1080
|
+
* `errCode` `chat_in_progress` until it has ended, `no_transcript` when it has no messages.
|
|
1081
|
+
*/
|
|
1082
|
+
rerunAnalysis(chatId, options) {
|
|
1083
|
+
return this._client.post(path`/v1/chats/${chatId}/rerun-analysis`, void 0, options);
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
|
|
1087
|
+
// src/resources/flows.ts
|
|
1088
|
+
var Flows = class extends APIResource {
|
|
1089
|
+
/** Validate and save a flow. `UnprocessableEntityError` (`errCode` `flow_invalid`) lists every problem. Not retried by default. */
|
|
1090
|
+
create(body, options) {
|
|
1091
|
+
return this._client.post("/v1/flows", body, options);
|
|
1092
|
+
}
|
|
1093
|
+
/** Flows, newest first. Await for one page, or iterate for every flow. Entries leave out `flow_config`. */
|
|
1094
|
+
list(params = {}, options) {
|
|
1095
|
+
const fetchPage = async (paginationKey) => {
|
|
1096
|
+
const res = await this._client.get(
|
|
1097
|
+
"/v1/flows",
|
|
1098
|
+
{ ...params, pagination_key: paginationKey ?? void 0 },
|
|
1099
|
+
options
|
|
1100
|
+
);
|
|
1101
|
+
return { data: res.flows, has_more: res.has_more, pagination_key: res.pagination_key };
|
|
1102
|
+
};
|
|
1103
|
+
return new PagePromise(fetchPage);
|
|
1104
|
+
}
|
|
1105
|
+
/** One flow with its `flow_config`. */
|
|
1106
|
+
retrieve(flowId, options) {
|
|
1107
|
+
return this._client.get(path`/v1/flows/${flowId}`, void 0, options);
|
|
1108
|
+
}
|
|
1109
|
+
/** Rename a flow and/or replace its `flow_config` (checked again). Agents it was attached to are not changed. */
|
|
1110
|
+
update(flowId, body, options) {
|
|
1111
|
+
return this._client.patch(path`/v1/flows/${flowId}`, body, options);
|
|
1112
|
+
}
|
|
1113
|
+
/** Delete a saved flow. Agents it was attached to keep their copy. */
|
|
1114
|
+
delete(flowId, options) {
|
|
1115
|
+
return this._client.delete(path`/v1/flows/${flowId}`, options);
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
// src/resources/llms.ts
|
|
1120
|
+
var LLMs = class extends APIResource {
|
|
1121
|
+
/** Save LLM settings. Anything left out takes the default a new agent gets. Not retried by default. */
|
|
1122
|
+
create(body, options) {
|
|
1123
|
+
return this._client.post("/v1/llms", body, options);
|
|
1124
|
+
}
|
|
1125
|
+
/** Saved LLMs, newest first. Await for one page, or iterate for every one. */
|
|
1126
|
+
list(params = {}, options) {
|
|
1127
|
+
const fetchPage = async (paginationKey) => {
|
|
1128
|
+
const res = await this._client.get(
|
|
1129
|
+
"/v1/llms",
|
|
1130
|
+
{ ...params, pagination_key: paginationKey ?? void 0 },
|
|
1131
|
+
options
|
|
1132
|
+
);
|
|
1133
|
+
return { data: res.llms, has_more: res.has_more, pagination_key: res.pagination_key };
|
|
1134
|
+
};
|
|
1135
|
+
return new PagePromise(fetchPage);
|
|
1136
|
+
}
|
|
1137
|
+
retrieve(llmId, options) {
|
|
1138
|
+
return this._client.get(path`/v1/llms/${llmId}`, void 0, options);
|
|
1139
|
+
}
|
|
1140
|
+
/** Change the fields you send. Agents it was attached to are not changed. */
|
|
1141
|
+
update(llmId, body, options) {
|
|
1142
|
+
return this._client.patch(path`/v1/llms/${llmId}`, body, options);
|
|
1143
|
+
}
|
|
1144
|
+
/** Delete saved LLM settings. Agents they were attached to keep their copy. */
|
|
1145
|
+
delete(llmId, options) {
|
|
1146
|
+
return this._client.delete(path`/v1/llms/${llmId}`, options);
|
|
1147
|
+
}
|
|
1148
|
+
};
|
|
1149
|
+
|
|
542
1150
|
// src/webhooks.ts
|
|
543
1151
|
var WEBHOOK_SIGNATURE_HEADER = "x-dialgem-signature";
|
|
544
1152
|
var WEBHOOK_EVENT_HEADER = "x-dialgem-event";
|
|
1153
|
+
var WEBHOOK_PREVIOUS_SIGNATURE_HEADER = "x-dialgem-signature-previous";
|
|
1154
|
+
var WEBHOOK_DELIVERY_HEADER = "x-dialgem-delivery";
|
|
1155
|
+
var DEFAULT_SIGNATURE_TOLERANCE_MS = 5 * 60 * 1e3;
|
|
545
1156
|
var encoder = new TextEncoder();
|
|
546
1157
|
var decoder = new TextDecoder();
|
|
1158
|
+
var SIGNATURE_RE = /^v=(\d{10,16}),d=([0-9a-f]{64})$/;
|
|
547
1159
|
var Webhooks = class {
|
|
548
1160
|
/**
|
|
549
|
-
* Returns whether `signature` is
|
|
550
|
-
* Constant-time. Returns `false` for a missing
|
|
551
|
-
* if `secret` is empty, which is a configuration
|
|
1161
|
+
* Returns whether `signature` is a current, valid signature of `payload` under
|
|
1162
|
+
* `secret`. Constant-time. Returns `false` for a missing, malformed, tampered or
|
|
1163
|
+
* stale signature; throws only if `secret` is empty, which is a configuration
|
|
1164
|
+
* error rather than a bad request.
|
|
552
1165
|
*/
|
|
553
|
-
async verify(payload, signature, secret) {
|
|
1166
|
+
async verify(payload, signature, secret, options = {}) {
|
|
554
1167
|
if (!secret) {
|
|
555
1168
|
throw new DialgemError(
|
|
556
1169
|
"Webhook secret is empty. Set the agent's `webhook_signing_secret` and pass the same value here."
|
|
557
1170
|
);
|
|
558
1171
|
}
|
|
559
|
-
const
|
|
560
|
-
if (!
|
|
561
|
-
const
|
|
1172
|
+
const match = SIGNATURE_RE.exec(firstHeader(signature)?.trim().toLowerCase() ?? "");
|
|
1173
|
+
if (!match) return false;
|
|
1174
|
+
const [, timestamp, received] = match;
|
|
1175
|
+
const now = options.now ?? Date.now();
|
|
1176
|
+
if (Math.abs(now - Number(timestamp)) > (options.toleranceMs ?? DEFAULT_SIGNATURE_TOLERANCE_MS)) {
|
|
1177
|
+
return false;
|
|
1178
|
+
}
|
|
1179
|
+
const body = toBytes(payload);
|
|
1180
|
+
const message = new Uint8Array(body.length + timestamp.length);
|
|
1181
|
+
message.set(body, 0);
|
|
1182
|
+
message.set(encoder.encode(timestamp), body.length);
|
|
1183
|
+
const expected = await hmacSha256Hex(secret, message);
|
|
562
1184
|
return timingSafeEqual(expected, received);
|
|
563
1185
|
}
|
|
564
1186
|
/**
|
|
565
|
-
* Verifies
|
|
1187
|
+
* Verifies a webhook's signature, then parses its body.
|
|
1188
|
+
*
|
|
1189
|
+
* @throws WebhookVerificationError if the signature is missing, invalid or stale.
|
|
1190
|
+
*/
|
|
1191
|
+
async constructEvent(payload, signature, secret, options = {}) {
|
|
1192
|
+
const parsed = await this.#verifiedJson(payload, signature, secret, options);
|
|
1193
|
+
if (typeof parsed !== "object" || parsed === null || typeof parsed.event !== "string") {
|
|
1194
|
+
throw new WebhookVerificationError("Webhook body has no `event` field.");
|
|
1195
|
+
}
|
|
1196
|
+
return parsed;
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
1199
|
+
* Verifies a request Dialgem made to one of your custom functions, then parses
|
|
1200
|
+
* its body. For functions with `args_at_root`, the body is the arguments object
|
|
1201
|
+
* alone; use `verify` and parse it yourself.
|
|
566
1202
|
*
|
|
567
|
-
* @throws WebhookVerificationError if the signature is missing or
|
|
1203
|
+
* @throws WebhookVerificationError if the signature is missing, invalid or stale.
|
|
568
1204
|
*/
|
|
569
|
-
async
|
|
1205
|
+
async constructFunctionCall(payload, signature, secret, options = {}) {
|
|
1206
|
+
const parsed = await this.#verifiedJson(payload, signature, secret, options);
|
|
1207
|
+
const body = parsed;
|
|
1208
|
+
if (!body || typeof body.name !== "string" || typeof body.call !== "object" || body.call === null) {
|
|
1209
|
+
throw new WebhookVerificationError(
|
|
1210
|
+
"Function request body has no `name` and `call`. Does this function have args_at_root set?"
|
|
1211
|
+
);
|
|
1212
|
+
}
|
|
1213
|
+
return body;
|
|
1214
|
+
}
|
|
1215
|
+
async #verifiedJson(payload, signature, secret, options) {
|
|
570
1216
|
if (!firstHeader(signature)) {
|
|
571
1217
|
throw new WebhookVerificationError(
|
|
572
1218
|
`Missing ${WEBHOOK_SIGNATURE_HEADER} header. Is a webhook_signing_secret set on the agent?`
|
|
573
1219
|
);
|
|
574
1220
|
}
|
|
575
|
-
if (!await this.verify(payload, signature, secret)) {
|
|
1221
|
+
if (!await this.verify(payload, signature, secret, options)) {
|
|
576
1222
|
throw new WebhookVerificationError(
|
|
577
|
-
"
|
|
1223
|
+
"Signature is invalid or older than the allowed tolerance. Check the secret, the server clock, and that the body was not re-serialized before verification."
|
|
578
1224
|
);
|
|
579
1225
|
}
|
|
580
1226
|
const text = typeof payload === "string" ? payload : decoder.decode(toBytes(payload));
|
|
581
|
-
let parsed;
|
|
582
1227
|
try {
|
|
583
|
-
|
|
1228
|
+
return JSON.parse(text);
|
|
584
1229
|
} catch {
|
|
585
|
-
throw new WebhookVerificationError("
|
|
586
|
-
}
|
|
587
|
-
if (typeof parsed !== "object" || parsed === null || typeof parsed.event !== "string") {
|
|
588
|
-
throw new WebhookVerificationError("Webhook body has no `event` field.");
|
|
1230
|
+
throw new WebhookVerificationError("Body is signed but is not valid JSON.");
|
|
589
1231
|
}
|
|
590
|
-
return parsed;
|
|
591
1232
|
}
|
|
592
1233
|
};
|
|
593
1234
|
var webhooks = new Webhooks();
|
|
@@ -617,22 +1258,50 @@ function timingSafeEqual(a, b) {
|
|
|
617
1258
|
}
|
|
618
1259
|
|
|
619
1260
|
// src/client.ts
|
|
620
|
-
var
|
|
1261
|
+
var BASE_URL = "https://api.dialgem.com";
|
|
621
1262
|
var DEFAULT_TIMEOUT_MS = 6e4;
|
|
622
1263
|
var DEFAULT_MAX_RETRIES = 2;
|
|
623
1264
|
var Dialgem = class {
|
|
624
|
-
static
|
|
1265
|
+
static BASE_URL = BASE_URL;
|
|
625
1266
|
/** Webhook verification without a client instance: `Dialgem.webhooks.constructEvent(...)`. */
|
|
626
1267
|
static webhooks = webhooks;
|
|
627
1268
|
agents;
|
|
628
1269
|
calls;
|
|
629
1270
|
phoneNumbers;
|
|
630
1271
|
voices;
|
|
1272
|
+
/** Models available for post-call analysis. */
|
|
1273
|
+
extractionModels;
|
|
631
1274
|
flowTemplates;
|
|
632
1275
|
promptTemplates;
|
|
1276
|
+
/** Calls in progress right now. */
|
|
1277
|
+
sessions;
|
|
1278
|
+
/** Text conversations with an agent. */
|
|
1279
|
+
chats;
|
|
1280
|
+
flows;
|
|
1281
|
+
llms;
|
|
1282
|
+
/** What this API key is and may do. */
|
|
1283
|
+
apiKey;
|
|
1284
|
+
/**
|
|
1285
|
+
* Verify what Dialgem sends you: `dialgem.webhooks.constructEvent(rawBody, signatureHeader, secret)`.
|
|
1286
|
+
*/
|
|
633
1287
|
webhooks = webhooks;
|
|
634
|
-
|
|
1288
|
+
/** The organization's webhook destinations: create, update, rotate the signing secret, test. */
|
|
1289
|
+
/** The people you call, with CSV import under `contacts.imports`. */
|
|
1290
|
+
contacts;
|
|
1291
|
+
/** Named groups of contacts. */
|
|
1292
|
+
contactLists;
|
|
1293
|
+
/** Browser calls: tokens for `@dialgem/client`, and the origins allowed to start them. */
|
|
1294
|
+
webCalls;
|
|
1295
|
+
/** Saved test conversations for an agent, run in text, with an optional publish gate. */
|
|
1296
|
+
simulations;
|
|
1297
|
+
/** Always `https://api.dialgem.com`. */
|
|
1298
|
+
baseURL = BASE_URL;
|
|
635
1299
|
constructor(options = {}) {
|
|
1300
|
+
if ("baseURL" in options) {
|
|
1301
|
+
throw new DialgemError(
|
|
1302
|
+
"`baseURL` is not an option: the SDK always talks to https://api.dialgem.com. Remove it."
|
|
1303
|
+
);
|
|
1304
|
+
}
|
|
636
1305
|
if (isBrowser() && !options.dangerouslyAllowBrowser) {
|
|
637
1306
|
throw new DialgemError(
|
|
638
1307
|
"The Dialgem SDK is for server-side use: running it in a browser exposes your API key to every visitor. Call Dialgem from your backend instead, or pass `dangerouslyAllowBrowser: true` if you understand the risk."
|
|
@@ -649,10 +1318,9 @@ var Dialgem = class {
|
|
|
649
1318
|
assertTimeout(timeout);
|
|
650
1319
|
assertMaxRetries(maxRetries);
|
|
651
1320
|
const fetchImpl = options.fetch ?? defaultFetch();
|
|
652
|
-
this.baseURL = (options.baseURL ?? readEnv("DIALGEM_BASE_URL") ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
653
1321
|
const http = new HttpClient({
|
|
654
1322
|
apiKey,
|
|
655
|
-
baseURL:
|
|
1323
|
+
baseURL: BASE_URL,
|
|
656
1324
|
timeout,
|
|
657
1325
|
maxRetries,
|
|
658
1326
|
fetch: fetchImpl,
|
|
@@ -662,8 +1330,18 @@ var Dialgem = class {
|
|
|
662
1330
|
this.calls = new Calls(http);
|
|
663
1331
|
this.phoneNumbers = new PhoneNumbers(http);
|
|
664
1332
|
this.voices = new Voices(http);
|
|
1333
|
+
this.extractionModels = new ExtractionModels(http);
|
|
665
1334
|
this.flowTemplates = new FlowTemplates(http);
|
|
666
1335
|
this.promptTemplates = new PromptTemplates(http);
|
|
1336
|
+
this.sessions = new Sessions(http);
|
|
1337
|
+
this.chats = new Chats(http);
|
|
1338
|
+
this.flows = new Flows(http);
|
|
1339
|
+
this.llms = new LLMs(http);
|
|
1340
|
+
this.apiKey = new ApiKey(http);
|
|
1341
|
+
this.contacts = new Contacts(http);
|
|
1342
|
+
this.contactLists = new ContactLists(http);
|
|
1343
|
+
this.webCalls = new WebCalls(http);
|
|
1344
|
+
this.simulations = new Simulations(http);
|
|
667
1345
|
}
|
|
668
1346
|
};
|
|
669
1347
|
function readEnv(name) {
|
|
@@ -683,6 +1361,6 @@ function defaultFetch() {
|
|
|
683
1361
|
return (url, init) => f.call(globalThis, url, init);
|
|
684
1362
|
}
|
|
685
1363
|
|
|
686
|
-
export { APIConnectionError, APIConnectionTimeoutError, APIError, APIUserAbortError, AuthenticationError, BadRequestError, ConflictError,
|
|
1364
|
+
export { APIConnectionError, APIConnectionTimeoutError, APIError, APIUserAbortError, AuthenticationError, BASE_URL, BadRequestError, ConflictError, DEFAULT_SIGNATURE_TOLERANCE_MS, Dialgem, DialgemError, InternalServerError, NotFoundError, Page, PagePromise, PermissionDeniedError, RateLimitError, UnprocessableEntityError, VERSION, WEBHOOK_DELIVERY_HEADER, WEBHOOK_EVENT_HEADER, WEBHOOK_PREVIOUS_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_HEADER, WebhookVerificationError, Webhooks, webhooks };
|
|
687
1365
|
//# sourceMappingURL=index.js.map
|
|
688
1366
|
//# sourceMappingURL=index.js.map
|