phonic 0.30.9 → 0.30.11
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/README.md +1 -1
- package/dist/cjs/Client.d.ts +2 -2
- package/dist/cjs/Client.js +2 -2
- package/dist/cjs/api/resources/agents/client/Client.d.ts +5 -5
- package/dist/cjs/api/resources/agents/client/Client.js +3 -3
- package/dist/cjs/api/resources/agents/client/requests/AgentsCreateRequest.d.ts +4 -2
- package/dist/cjs/api/resources/agents/client/requests/UpdateAgentRequest.d.ts +13 -2
- package/dist/cjs/api/resources/agents/client/requests/UpdateAgentRequest.js +5 -0
- package/dist/cjs/api/resources/agents/client/requests/UpsertAgentRequest.d.ts +1 -1
- package/dist/cjs/api/resources/conversations/client/Client.d.ts +3 -3
- package/dist/cjs/api/resources/conversations/client/Client.js +1 -1
- package/dist/cjs/api/resources/conversations/client/requests/OutboundCallRequest.d.ts +1 -1
- package/dist/cjs/api/resources/extractionSchemas/client/Client.d.ts +2 -2
- package/dist/cjs/api/resources/projects/client/Client.d.ts +2 -2
- package/dist/cjs/api/resources/tools/client/Client.d.ts +2 -2
- package/dist/cjs/api/resources/voices/client/Client.d.ts +2 -2
- package/dist/cjs/api/types/Agent.d.ts +12 -1
- package/dist/cjs/api/types/Agent.js +5 -0
- package/dist/cjs/api/types/ConfigPayload.d.ts +11 -0
- package/dist/cjs/api/types/ConfigPayload.js +5 -0
- package/dist/cjs/api/types/Conversation.d.ts +23 -2
- package/dist/cjs/api/types/Conversation.js +5 -0
- package/dist/cjs/api/types/CreateAgentRequest.d.ts +12 -1
- package/dist/cjs/api/types/CreateAgentRequest.js +5 -0
- package/dist/cjs/api/types/LanguageCode.d.ts +28 -0
- package/dist/cjs/api/types/LanguageCode.js +27 -0
- package/dist/cjs/api/types/OutboundCallConfig.d.ts +2 -1
- package/dist/cjs/api/types/index.d.ts +1 -0
- package/dist/cjs/api/types/index.js +1 -0
- package/dist/cjs/core/fetcher/Fetcher.d.ts +1 -1
- package/dist/cjs/core/fetcher/requestWithRetries.js +44 -8
- package/dist/cjs/core/headers.d.ts +2 -2
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Client.d.mts +2 -2
- package/dist/esm/Client.mjs +2 -2
- package/dist/esm/api/resources/agents/client/Client.d.mts +5 -5
- package/dist/esm/api/resources/agents/client/Client.mjs +3 -3
- package/dist/esm/api/resources/agents/client/requests/AgentsCreateRequest.d.mts +4 -2
- package/dist/esm/api/resources/agents/client/requests/UpdateAgentRequest.d.mts +13 -2
- package/dist/esm/api/resources/agents/client/requests/UpdateAgentRequest.mjs +5 -0
- package/dist/esm/api/resources/agents/client/requests/UpsertAgentRequest.d.mts +1 -1
- package/dist/esm/api/resources/conversations/client/Client.d.mts +3 -3
- package/dist/esm/api/resources/conversations/client/Client.mjs +1 -1
- package/dist/esm/api/resources/conversations/client/requests/OutboundCallRequest.d.mts +1 -1
- package/dist/esm/api/resources/extractionSchemas/client/Client.d.mts +2 -2
- package/dist/esm/api/resources/projects/client/Client.d.mts +2 -2
- package/dist/esm/api/resources/tools/client/Client.d.mts +2 -2
- package/dist/esm/api/resources/voices/client/Client.d.mts +2 -2
- package/dist/esm/api/types/Agent.d.mts +12 -1
- package/dist/esm/api/types/Agent.mjs +5 -0
- package/dist/esm/api/types/ConfigPayload.d.mts +11 -0
- package/dist/esm/api/types/ConfigPayload.mjs +5 -0
- package/dist/esm/api/types/Conversation.d.mts +23 -2
- package/dist/esm/api/types/Conversation.mjs +5 -0
- package/dist/esm/api/types/CreateAgentRequest.d.mts +12 -1
- package/dist/esm/api/types/CreateAgentRequest.mjs +5 -0
- package/dist/esm/api/types/LanguageCode.d.mts +28 -0
- package/dist/esm/api/types/LanguageCode.mjs +24 -0
- package/dist/esm/api/types/OutboundCallConfig.d.mts +2 -1
- package/dist/esm/api/types/index.d.mts +1 -0
- package/dist/esm/api/types/index.mjs +1 -0
- package/dist/esm/core/fetcher/Fetcher.d.mts +1 -1
- package/dist/esm/core/fetcher/requestWithRetries.mjs +44 -8
- package/dist/esm/core/headers.d.mts +2 -2
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -1
- package/reference.md +4 -4
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
+
*/
|
|
4
|
+
export const LanguageCode = {
|
|
5
|
+
Ar: "ar",
|
|
6
|
+
Zh: "zh",
|
|
7
|
+
Cs: "cs",
|
|
8
|
+
Da: "da",
|
|
9
|
+
Nl: "nl",
|
|
10
|
+
En: "en",
|
|
11
|
+
Fr: "fr",
|
|
12
|
+
De: "de",
|
|
13
|
+
Id: "id",
|
|
14
|
+
It: "it",
|
|
15
|
+
Ja: "ja",
|
|
16
|
+
Ko: "ko",
|
|
17
|
+
Pl: "pl",
|
|
18
|
+
Pt: "pt",
|
|
19
|
+
Ru: "ru",
|
|
20
|
+
Es: "es",
|
|
21
|
+
Sv: "sv",
|
|
22
|
+
Tr: "tr",
|
|
23
|
+
Vi: "vi",
|
|
24
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This file was auto-generated by Fern from our API Definition.
|
|
3
3
|
*/
|
|
4
|
+
import * as Phonic from "../index.mjs";
|
|
4
5
|
/**
|
|
5
6
|
* When an `agent` is provided, these `config` options override the agent settings.
|
|
6
7
|
*/
|
|
@@ -24,7 +25,7 @@ export interface OutboundCallConfig {
|
|
|
24
25
|
/** Seconds of silence before ending the conversation. */
|
|
25
26
|
no_input_end_conversation_sec?: number;
|
|
26
27
|
/** Array of ISO 639-1 language codes that the agent should be able to recognize */
|
|
27
|
-
|
|
28
|
+
languages?: Phonic.LanguageCode[];
|
|
28
29
|
/** These words, or short phrases, will be more accurately recognized by the agent. */
|
|
29
30
|
boosted_keywords?: string[];
|
|
30
31
|
/** Array of built-in or custom tool names to use. */
|
|
@@ -2,6 +2,7 @@ export * from "./BadRequestErrorBody.mjs";
|
|
|
2
2
|
export * from "./Error_.mjs";
|
|
3
3
|
export * from "./BasicError.mjs";
|
|
4
4
|
export * from "./ValidationError.mjs";
|
|
5
|
+
export * from "./LanguageCode.mjs";
|
|
5
6
|
export * from "./Agent.mjs";
|
|
6
7
|
export * from "./CreateAgentRequest.mjs";
|
|
7
8
|
export * from "./Tool.mjs";
|
|
@@ -2,6 +2,7 @@ export * from "./BadRequestErrorBody.mjs";
|
|
|
2
2
|
export * from "./Error_.mjs";
|
|
3
3
|
export * from "./BasicError.mjs";
|
|
4
4
|
export * from "./ValidationError.mjs";
|
|
5
|
+
export * from "./LanguageCode.mjs";
|
|
5
6
|
export * from "./Agent.mjs";
|
|
6
7
|
export * from "./CreateAgentRequest.mjs";
|
|
7
8
|
export * from "./Tool.mjs";
|
|
@@ -6,7 +6,7 @@ export declare namespace Fetcher {
|
|
|
6
6
|
url: string;
|
|
7
7
|
method: string;
|
|
8
8
|
contentType?: string;
|
|
9
|
-
headers?: Record<string, string | Supplier<string | undefined> | undefined>;
|
|
9
|
+
headers?: Record<string, string | Supplier<string | null | undefined> | null | undefined>;
|
|
10
10
|
queryParameters?: Record<string, unknown>;
|
|
11
11
|
body?: unknown;
|
|
12
12
|
timeoutMs?: number;
|
|
@@ -11,21 +11,57 @@ const INITIAL_RETRY_DELAY = 1000; // in milliseconds
|
|
|
11
11
|
const MAX_RETRY_DELAY = 60000; // in milliseconds
|
|
12
12
|
const DEFAULT_MAX_RETRIES = 2;
|
|
13
13
|
const JITTER_FACTOR = 0.2; // 20% random jitter
|
|
14
|
-
function
|
|
15
|
-
// Generate a random value between
|
|
16
|
-
const jitterMultiplier = 1 +
|
|
14
|
+
function addPositiveJitter(delay) {
|
|
15
|
+
// Generate a random value between 0 and +JITTER_FACTOR
|
|
16
|
+
const jitterMultiplier = 1 + Math.random() * JITTER_FACTOR;
|
|
17
17
|
return delay * jitterMultiplier;
|
|
18
18
|
}
|
|
19
|
+
function addSymmetricJitter(delay) {
|
|
20
|
+
// Generate a random value in a JITTER_FACTOR-sized percentage range around delay
|
|
21
|
+
const jitterMultiplier = 1 + (Math.random() - 0.5) * JITTER_FACTOR;
|
|
22
|
+
return delay * jitterMultiplier;
|
|
23
|
+
}
|
|
24
|
+
function getRetryDelayFromHeaders(response, retryAttempt) {
|
|
25
|
+
// Check for Retry-After header first (RFC 7231), with no jitter
|
|
26
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
27
|
+
if (retryAfter) {
|
|
28
|
+
// Parse as number of seconds...
|
|
29
|
+
const retryAfterSeconds = parseInt(retryAfter, 10);
|
|
30
|
+
if (!isNaN(retryAfterSeconds) && retryAfterSeconds > 0) {
|
|
31
|
+
return Math.min(retryAfterSeconds * 1000, MAX_RETRY_DELAY);
|
|
32
|
+
}
|
|
33
|
+
// ...or as an HTTP date; both are valid
|
|
34
|
+
const retryAfterDate = new Date(retryAfter);
|
|
35
|
+
if (!isNaN(retryAfterDate.getTime())) {
|
|
36
|
+
const delay = retryAfterDate.getTime() - Date.now();
|
|
37
|
+
if (delay > 0) {
|
|
38
|
+
return Math.min(Math.max(delay, 0), MAX_RETRY_DELAY);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Then check for industry-standard X-RateLimit-Reset header, with positive jitter
|
|
43
|
+
const rateLimitReset = response.headers.get("X-RateLimit-Reset");
|
|
44
|
+
if (rateLimitReset) {
|
|
45
|
+
const resetTime = parseInt(rateLimitReset, 10);
|
|
46
|
+
if (!isNaN(resetTime)) {
|
|
47
|
+
// Assume Unix timestamp in epoch seconds
|
|
48
|
+
const delay = resetTime * 1000 - Date.now();
|
|
49
|
+
if (delay > 0) {
|
|
50
|
+
return addPositiveJitter(Math.min(delay, MAX_RETRY_DELAY));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Fall back to exponential backoff, with symmetric jitter
|
|
55
|
+
return addSymmetricJitter(Math.min(INITIAL_RETRY_DELAY * Math.pow(2, retryAttempt), MAX_RETRY_DELAY));
|
|
56
|
+
}
|
|
19
57
|
export function requestWithRetries(requestFn_1) {
|
|
20
58
|
return __awaiter(this, arguments, void 0, function* (requestFn, maxRetries = DEFAULT_MAX_RETRIES) {
|
|
21
59
|
let response = yield requestFn();
|
|
22
60
|
for (let i = 0; i < maxRetries; ++i) {
|
|
23
61
|
if ([408, 429].includes(response.status) || response.status >= 500) {
|
|
24
|
-
//
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
const delayWithJitter = addJitter(baseDelay);
|
|
28
|
-
yield new Promise((resolve) => setTimeout(resolve, delayWithJitter));
|
|
62
|
+
// Get delay with appropriate jitter applied
|
|
63
|
+
const delay = getRetryDelayFromHeaders(response, i);
|
|
64
|
+
yield new Promise((resolve) => setTimeout(resolve, delay));
|
|
29
65
|
response = yield requestFn();
|
|
30
66
|
}
|
|
31
67
|
else {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as core from "./index.mjs";
|
|
2
|
-
export declare function mergeHeaders(...headersArray: (Record<string, string | core.Supplier<string | undefined> | undefined> | undefined)[]): Record<string, string | core.Supplier<string | undefined>>;
|
|
3
|
-
export declare function mergeOnlyDefinedHeaders(...headersArray: (Record<string, string | core.Supplier<string | undefined> | undefined> | undefined)[]): Record<string, string | core.Supplier<string | undefined>>;
|
|
2
|
+
export declare function mergeHeaders(...headersArray: (Record<string, string | core.Supplier<string | null | undefined> | null | undefined> | null | undefined)[]): Record<string, string | core.Supplier<string | null | undefined>>;
|
|
3
|
+
export declare function mergeOnlyDefinedHeaders(...headersArray: (Record<string, string | core.Supplier<string | null | undefined> | null | undefined> | null | undefined)[]): Record<string, string | core.Supplier<string | null | undefined>>;
|
package/dist/esm/version.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.30.
|
|
1
|
+
export declare const SDK_VERSION = "0.30.11";
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.30.
|
|
1
|
+
export const SDK_VERSION = "0.30.11";
|
package/package.json
CHANGED
package/reference.md
CHANGED
|
@@ -114,7 +114,7 @@ await client.agents.create({
|
|
|
114
114
|
tools: ["keypad_input"],
|
|
115
115
|
no_input_poke_sec: 30,
|
|
116
116
|
no_input_poke_text: "Are you still there?",
|
|
117
|
-
|
|
117
|
+
languages: ["en", "es"],
|
|
118
118
|
boosted_keywords: ["Load ID", "dispatch"],
|
|
119
119
|
configuration_endpoint: {
|
|
120
120
|
url: "https://api.example.com/config",
|
|
@@ -207,7 +207,7 @@ await client.agents.upsert({
|
|
|
207
207
|
tools: ["keypad_input"],
|
|
208
208
|
no_input_poke_sec: 30,
|
|
209
209
|
no_input_poke_text: "Are you still there?",
|
|
210
|
-
|
|
210
|
+
languages: ["en", "es"],
|
|
211
211
|
boosted_keywords: ["Load ID", "dispatch"],
|
|
212
212
|
configuration_endpoint: {
|
|
213
213
|
url: "https://api.example.com/config",
|
|
@@ -446,7 +446,7 @@ await client.agents.update("nameOrId", {
|
|
|
446
446
|
tools: ["keypad_input"],
|
|
447
447
|
no_input_poke_sec: 30,
|
|
448
448
|
no_input_poke_text: "Are you still there?",
|
|
449
|
-
|
|
449
|
+
languages: ["en", "es"],
|
|
450
450
|
boosted_keywords: ["Load ID", "dispatch"],
|
|
451
451
|
configuration_endpoint: {
|
|
452
452
|
url: "https://api.example.com/config",
|
|
@@ -1961,7 +1961,7 @@ await client.conversations.outboundCall({
|
|
|
1961
1961
|
no_input_poke_sec: 30,
|
|
1962
1962
|
no_input_poke_text: "Are you still there?",
|
|
1963
1963
|
no_input_end_conversation_sec: 180,
|
|
1964
|
-
|
|
1964
|
+
languages: ["en", "es"],
|
|
1965
1965
|
boosted_keywords: ["Load ID", "dispatch"],
|
|
1966
1966
|
tools: ["keypad_input"],
|
|
1967
1967
|
},
|