phonic 0.30.10 → 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.
Files changed (49) hide show
  1. package/dist/cjs/Client.d.ts +2 -2
  2. package/dist/cjs/Client.js +2 -2
  3. package/dist/cjs/api/resources/agents/client/Client.d.ts +2 -2
  4. package/dist/cjs/api/resources/agents/client/requests/AgentsCreateRequest.d.ts +2 -0
  5. package/dist/cjs/api/resources/agents/client/requests/UpdateAgentRequest.d.ts +11 -0
  6. package/dist/cjs/api/resources/agents/client/requests/UpdateAgentRequest.js +5 -0
  7. package/dist/cjs/api/resources/conversations/client/Client.d.ts +2 -2
  8. package/dist/cjs/api/resources/extractionSchemas/client/Client.d.ts +2 -2
  9. package/dist/cjs/api/resources/projects/client/Client.d.ts +2 -2
  10. package/dist/cjs/api/resources/tools/client/Client.d.ts +2 -2
  11. package/dist/cjs/api/resources/voices/client/Client.d.ts +2 -2
  12. package/dist/cjs/api/types/Agent.d.ts +11 -0
  13. package/dist/cjs/api/types/Agent.js +5 -0
  14. package/dist/cjs/api/types/ConfigPayload.d.ts +11 -0
  15. package/dist/cjs/api/types/ConfigPayload.js +5 -0
  16. package/dist/cjs/api/types/Conversation.d.ts +11 -0
  17. package/dist/cjs/api/types/Conversation.js +5 -0
  18. package/dist/cjs/api/types/CreateAgentRequest.d.ts +11 -0
  19. package/dist/cjs/api/types/CreateAgentRequest.js +5 -0
  20. package/dist/cjs/core/fetcher/Fetcher.d.ts +1 -1
  21. package/dist/cjs/core/fetcher/requestWithRetries.js +44 -8
  22. package/dist/cjs/core/headers.d.ts +2 -2
  23. package/dist/cjs/version.d.ts +1 -1
  24. package/dist/cjs/version.js +1 -1
  25. package/dist/esm/Client.d.mts +2 -2
  26. package/dist/esm/Client.mjs +2 -2
  27. package/dist/esm/api/resources/agents/client/Client.d.mts +2 -2
  28. package/dist/esm/api/resources/agents/client/requests/AgentsCreateRequest.d.mts +2 -0
  29. package/dist/esm/api/resources/agents/client/requests/UpdateAgentRequest.d.mts +11 -0
  30. package/dist/esm/api/resources/agents/client/requests/UpdateAgentRequest.mjs +5 -0
  31. package/dist/esm/api/resources/conversations/client/Client.d.mts +2 -2
  32. package/dist/esm/api/resources/extractionSchemas/client/Client.d.mts +2 -2
  33. package/dist/esm/api/resources/projects/client/Client.d.mts +2 -2
  34. package/dist/esm/api/resources/tools/client/Client.d.mts +2 -2
  35. package/dist/esm/api/resources/voices/client/Client.d.mts +2 -2
  36. package/dist/esm/api/types/Agent.d.mts +11 -0
  37. package/dist/esm/api/types/Agent.mjs +5 -0
  38. package/dist/esm/api/types/ConfigPayload.d.mts +11 -0
  39. package/dist/esm/api/types/ConfigPayload.mjs +5 -0
  40. package/dist/esm/api/types/Conversation.d.mts +11 -0
  41. package/dist/esm/api/types/Conversation.mjs +5 -0
  42. package/dist/esm/api/types/CreateAgentRequest.d.mts +11 -0
  43. package/dist/esm/api/types/CreateAgentRequest.mjs +5 -0
  44. package/dist/esm/core/fetcher/Fetcher.d.mts +1 -1
  45. package/dist/esm/core/fetcher/requestWithRetries.mjs +44 -8
  46. package/dist/esm/core/headers.d.mts +2 -2
  47. package/dist/esm/version.d.mts +1 -1
  48. package/dist/esm/version.mjs +1 -1
  49. package/package.json +1 -1
@@ -16,7 +16,7 @@ export declare namespace PhonicClient {
16
16
  baseUrl?: core.Supplier<string>;
17
17
  apiKey?: core.Supplier<core.BearerToken | undefined>;
18
18
  /** Additional headers to include in requests. */
19
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
19
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
20
20
  fetcher?: core.FetchFunction;
21
21
  }
22
22
  interface RequestOptions {
@@ -29,7 +29,7 @@ export declare namespace PhonicClient {
29
29
  /** Additional query string parameters to include in the request. */
30
30
  queryParams?: Record<string, unknown>;
31
31
  /** Additional headers to include in the request. */
32
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
32
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
33
33
  }
34
34
  }
35
35
  export declare class PhonicClient {
@@ -50,8 +50,8 @@ class PhonicClient {
50
50
  this._options = Object.assign(Object.assign({}, _options), { headers: (0, headers_js_1.mergeHeaders)({
51
51
  "X-Fern-Language": "JavaScript",
52
52
  "X-Fern-SDK-Name": "phonic",
53
- "X-Fern-SDK-Version": "0.30.10",
54
- "User-Agent": "phonic/0.30.10",
53
+ "X-Fern-SDK-Version": "0.30.11",
54
+ "User-Agent": "phonic/0.30.11",
55
55
  "X-Fern-Runtime": core.RUNTIME.type,
56
56
  "X-Fern-Runtime-Version": core.RUNTIME.version,
57
57
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -11,7 +11,7 @@ export declare namespace Agents {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace Agents {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class Agents {
@@ -52,6 +52,8 @@ export interface AgentsCreateRequest {
52
52
  audio_speed?: number;
53
53
  /** The background noise level of the agent. */
54
54
  background_noise_level?: number;
55
+ /** The background noise type. Can be "office", "call-center", "coffee-shop", or null. */
56
+ background_noise?: Phonic.CreateAgentRequest.BackgroundNoise | null;
55
57
  /** Message to play when the conversation starts. Can contain template variables like `{{customer_name}}`. */
56
58
  welcome_message?: string;
57
59
  /** Instructions for the conversation. Can contain template variables like `{{subject}}`. */
@@ -52,6 +52,8 @@ export interface UpdateAgentRequest {
52
52
  audio_speed?: number;
53
53
  /** The background noise level of the agent. */
54
54
  background_noise_level?: number;
55
+ /** The background noise type. Can be "office", "call-center", "coffee-shop", or null. */
56
+ background_noise?: UpdateAgentRequest.BackgroundNoise | null;
55
57
  /** Message to play when the conversation starts. Can contain template variables like `{{customer_name}}`. */
56
58
  welcome_message?: string;
57
59
  /** Instructions for the conversation. Can contain template variables like `{{subject}}`. */
@@ -86,6 +88,15 @@ export declare namespace UpdateAgentRequest {
86
88
  readonly Pcm8000: "pcm_8000";
87
89
  readonly Mulaw8000: "mulaw_8000";
88
90
  };
91
+ /**
92
+ * The background noise type. Can be "office", "call-center", "coffee-shop", or null.
93
+ */
94
+ type BackgroundNoise = "office" | "call-center" | "coffee-shop";
95
+ const BackgroundNoise: {
96
+ readonly Office: "office";
97
+ readonly CallCenter: "call-center";
98
+ readonly CoffeeShop: "coffee-shop";
99
+ };
89
100
  namespace TemplateVariables {
90
101
  interface Value {
91
102
  default_value: string | null;
@@ -12,4 +12,9 @@ var UpdateAgentRequest;
12
12
  Pcm8000: "pcm_8000",
13
13
  Mulaw8000: "mulaw_8000",
14
14
  };
15
+ UpdateAgentRequest.BackgroundNoise = {
16
+ Office: "office",
17
+ CallCenter: "call-center",
18
+ CoffeeShop: "coffee-shop",
19
+ };
15
20
  })(UpdateAgentRequest || (exports.UpdateAgentRequest = UpdateAgentRequest = {}));
@@ -12,7 +12,7 @@ export declare namespace Conversations {
12
12
  baseUrl?: core.Supplier<string>;
13
13
  apiKey?: core.Supplier<core.BearerToken | undefined>;
14
14
  /** Additional headers to include in requests. */
15
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
15
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
16
16
  fetcher?: core.FetchFunction;
17
17
  }
18
18
  interface RequestOptions {
@@ -25,7 +25,7 @@ export declare namespace Conversations {
25
25
  /** Additional query string parameters to include in the request. */
26
26
  queryParams?: Record<string, unknown>;
27
27
  /** Additional headers to include in the request. */
28
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
28
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
29
29
  }
30
30
  interface ConnectArgs {
31
31
  downstream_websocket_url?: string | undefined;
@@ -11,7 +11,7 @@ export declare namespace ExtractionSchemas {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace ExtractionSchemas {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class ExtractionSchemas {
@@ -11,7 +11,7 @@ export declare namespace Projects {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace Projects {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class Projects {
@@ -11,7 +11,7 @@ export declare namespace Tools {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace Tools {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class Tools {
@@ -11,7 +11,7 @@ export declare namespace Voices {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace Voices {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class Voices {
@@ -21,6 +21,8 @@ export interface Agent {
21
21
  audio_speed: number;
22
22
  /** The background noise level of the agent. Must be between 0 and 1. */
23
23
  background_noise_level: number;
24
+ /** The background noise type. Can be "office", "call-center", "coffee-shop", or null. */
25
+ background_noise: Agent.BackgroundNoise | null;
24
26
  /** Message to play when the conversation starts. */
25
27
  welcome_message: string | null;
26
28
  /** Instructions for the conversation. */
@@ -62,6 +64,15 @@ export declare namespace Agent {
62
64
  readonly Pcm8000: "pcm_8000";
63
65
  readonly Mulaw8000: "mulaw_8000";
64
66
  };
67
+ /**
68
+ * The background noise type. Can be "office", "call-center", "coffee-shop", or null.
69
+ */
70
+ type BackgroundNoise = "office" | "call-center" | "coffee-shop";
71
+ const BackgroundNoise: {
72
+ readonly Office: "office";
73
+ readonly CallCenter: "call-center";
74
+ readonly CoffeeShop: "coffee-shop";
75
+ };
65
76
  namespace TemplateVariables {
66
77
  interface Value {
67
78
  default_value: string | null;
@@ -12,4 +12,9 @@ var Agent;
12
12
  Pcm8000: "pcm_8000",
13
13
  Mulaw8000: "mulaw_8000",
14
14
  };
15
+ Agent.BackgroundNoise = {
16
+ Office: "office",
17
+ CallCenter: "call-center",
18
+ CoffeeShop: "coffee-shop",
19
+ };
15
20
  })(Agent || (exports.Agent = Agent = {}));
@@ -15,6 +15,8 @@ export interface ConfigPayload {
15
15
  audio_speed?: number;
16
16
  /** Background noise level for the conversation */
17
17
  background_noise_level?: number;
18
+ /** Background noise type for the conversation */
19
+ background_noise?: ConfigPayload.BackgroundNoise | null;
18
20
  /** Message to play when conversation starts */
19
21
  welcome_message?: string | null;
20
22
  /** Voice ID to use for speech synthesis */
@@ -51,6 +53,15 @@ export interface ConfigPayload {
51
53
  template_variables?: Record<string, string>;
52
54
  }
53
55
  export declare namespace ConfigPayload {
56
+ /**
57
+ * Background noise type for the conversation
58
+ */
59
+ type BackgroundNoise = "office" | "call-center" | "coffee-shop";
60
+ const BackgroundNoise: {
61
+ readonly Office: "office";
62
+ readonly CallCenter: "call-center";
63
+ readonly CoffeeShop: "coffee-shop";
64
+ };
54
65
  /**
55
66
  * Audio input format
56
67
  */
@@ -6,6 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ConfigPayload = void 0;
7
7
  var ConfigPayload;
8
8
  (function (ConfigPayload) {
9
+ ConfigPayload.BackgroundNoise = {
10
+ Office: "office",
11
+ CallCenter: "call-center",
12
+ CoffeeShop: "coffee-shop",
13
+ };
9
14
  ConfigPayload.InputFormat = {
10
15
  Pcm44100: "pcm_44100",
11
16
  Pcm16000: "pcm_16000",
@@ -25,6 +25,8 @@ export interface Conversation {
25
25
  output_format: string;
26
26
  /** Background noise level used in the conversation. */
27
27
  background_noise_level: number;
28
+ /** The background noise type used in the conversation. */
29
+ background_noise: Conversation.BackgroundNoise | null;
28
30
  /** Live transcript of the conversation. */
29
31
  live_transcript: string;
30
32
  /** Post-call processed transcript. */
@@ -75,6 +77,15 @@ export declare namespace Conversation {
75
77
  /** The name of the project. */
76
78
  name: string;
77
79
  }
80
+ /**
81
+ * The background noise type used in the conversation.
82
+ */
83
+ type BackgroundNoise = "office" | "call-center" | "coffee-shop";
84
+ const BackgroundNoise: {
85
+ readonly Office: "office";
86
+ readonly CallCenter: "call-center";
87
+ readonly CoffeeShop: "coffee-shop";
88
+ };
78
89
  /**
79
90
  * Who or what ended the conversation.
80
91
  */
@@ -6,6 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Conversation = void 0;
7
7
  var Conversation;
8
8
  (function (Conversation) {
9
+ Conversation.BackgroundNoise = {
10
+ Office: "office",
11
+ CallCenter: "call-center",
12
+ CoffeeShop: "coffee-shop",
13
+ };
9
14
  Conversation.EndedBy = {
10
15
  User: "user",
11
16
  UserCanceled: "user_canceled",
@@ -16,6 +16,8 @@ export interface CreateAgentRequest {
16
16
  audio_speed?: number;
17
17
  /** The background noise level of the agent. */
18
18
  background_noise_level?: number;
19
+ /** The background noise type. Can be "office", "call-center", "coffee-shop", or null. */
20
+ background_noise?: CreateAgentRequest.BackgroundNoise | null;
19
21
  /** Message to play when the conversation starts. Can contain template variables like `{{customer_name}}`. */
20
22
  welcome_message?: string;
21
23
  /** Instructions for the conversation. Can contain template variables like `{{subject}}`. */
@@ -50,6 +52,15 @@ export declare namespace CreateAgentRequest {
50
52
  readonly Pcm8000: "pcm_8000";
51
53
  readonly Mulaw8000: "mulaw_8000";
52
54
  };
55
+ /**
56
+ * The background noise type. Can be "office", "call-center", "coffee-shop", or null.
57
+ */
58
+ type BackgroundNoise = "office" | "call-center" | "coffee-shop";
59
+ const BackgroundNoise: {
60
+ readonly Office: "office";
61
+ readonly CallCenter: "call-center";
62
+ readonly CoffeeShop: "coffee-shop";
63
+ };
53
64
  namespace TemplateVariables {
54
65
  interface Value {
55
66
  default_value: string | null;
@@ -12,4 +12,9 @@ var CreateAgentRequest;
12
12
  Pcm8000: "pcm_8000",
13
13
  Mulaw8000: "mulaw_8000",
14
14
  };
15
+ CreateAgentRequest.BackgroundNoise = {
16
+ Office: "office",
17
+ CallCenter: "call-center",
18
+ CoffeeShop: "coffee-shop",
19
+ };
15
20
  })(CreateAgentRequest || (exports.CreateAgentRequest = CreateAgentRequest = {}));
@@ -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;
@@ -14,21 +14,57 @@ const INITIAL_RETRY_DELAY = 1000; // in milliseconds
14
14
  const MAX_RETRY_DELAY = 60000; // in milliseconds
15
15
  const DEFAULT_MAX_RETRIES = 2;
16
16
  const JITTER_FACTOR = 0.2; // 20% random jitter
17
- function addJitter(delay) {
18
- // Generate a random value between -JITTER_FACTOR and +JITTER_FACTOR
19
- const jitterMultiplier = 1 + (Math.random() * 2 - 1) * JITTER_FACTOR;
17
+ function addPositiveJitter(delay) {
18
+ // Generate a random value between 0 and +JITTER_FACTOR
19
+ const jitterMultiplier = 1 + Math.random() * JITTER_FACTOR;
20
20
  return delay * jitterMultiplier;
21
21
  }
22
+ function addSymmetricJitter(delay) {
23
+ // Generate a random value in a JITTER_FACTOR-sized percentage range around delay
24
+ const jitterMultiplier = 1 + (Math.random() - 0.5) * JITTER_FACTOR;
25
+ return delay * jitterMultiplier;
26
+ }
27
+ function getRetryDelayFromHeaders(response, retryAttempt) {
28
+ // Check for Retry-After header first (RFC 7231), with no jitter
29
+ const retryAfter = response.headers.get("Retry-After");
30
+ if (retryAfter) {
31
+ // Parse as number of seconds...
32
+ const retryAfterSeconds = parseInt(retryAfter, 10);
33
+ if (!isNaN(retryAfterSeconds) && retryAfterSeconds > 0) {
34
+ return Math.min(retryAfterSeconds * 1000, MAX_RETRY_DELAY);
35
+ }
36
+ // ...or as an HTTP date; both are valid
37
+ const retryAfterDate = new Date(retryAfter);
38
+ if (!isNaN(retryAfterDate.getTime())) {
39
+ const delay = retryAfterDate.getTime() - Date.now();
40
+ if (delay > 0) {
41
+ return Math.min(Math.max(delay, 0), MAX_RETRY_DELAY);
42
+ }
43
+ }
44
+ }
45
+ // Then check for industry-standard X-RateLimit-Reset header, with positive jitter
46
+ const rateLimitReset = response.headers.get("X-RateLimit-Reset");
47
+ if (rateLimitReset) {
48
+ const resetTime = parseInt(rateLimitReset, 10);
49
+ if (!isNaN(resetTime)) {
50
+ // Assume Unix timestamp in epoch seconds
51
+ const delay = resetTime * 1000 - Date.now();
52
+ if (delay > 0) {
53
+ return addPositiveJitter(Math.min(delay, MAX_RETRY_DELAY));
54
+ }
55
+ }
56
+ }
57
+ // Fall back to exponential backoff, with symmetric jitter
58
+ return addSymmetricJitter(Math.min(INITIAL_RETRY_DELAY * Math.pow(2, retryAttempt), MAX_RETRY_DELAY));
59
+ }
22
60
  function requestWithRetries(requestFn_1) {
23
61
  return __awaiter(this, arguments, void 0, function* (requestFn, maxRetries = DEFAULT_MAX_RETRIES) {
24
62
  let response = yield requestFn();
25
63
  for (let i = 0; i < maxRetries; ++i) {
26
64
  if ([408, 429].includes(response.status) || response.status >= 500) {
27
- // Calculate base delay using exponential backoff (in milliseconds)
28
- const baseDelay = Math.min(INITIAL_RETRY_DELAY * Math.pow(2, i), MAX_RETRY_DELAY);
29
- // Add jitter to the delay
30
- const delayWithJitter = addJitter(baseDelay);
31
- yield new Promise((resolve) => setTimeout(resolve, delayWithJitter));
65
+ // Get delay with appropriate jitter applied
66
+ const delay = getRetryDelayFromHeaders(response, i);
67
+ yield new Promise((resolve) => setTimeout(resolve, delay));
32
68
  response = yield requestFn();
33
69
  }
34
70
  else {
@@ -1,3 +1,3 @@
1
1
  import * as core from "./index.js";
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>>;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.30.10";
1
+ export declare const SDK_VERSION = "0.30.11";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "0.30.10";
4
+ exports.SDK_VERSION = "0.30.11";
@@ -16,7 +16,7 @@ export declare namespace PhonicClient {
16
16
  baseUrl?: core.Supplier<string>;
17
17
  apiKey?: core.Supplier<core.BearerToken | undefined>;
18
18
  /** Additional headers to include in requests. */
19
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
19
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
20
20
  fetcher?: core.FetchFunction;
21
21
  }
22
22
  interface RequestOptions {
@@ -29,7 +29,7 @@ export declare namespace PhonicClient {
29
29
  /** Additional query string parameters to include in the request. */
30
30
  queryParams?: Record<string, unknown>;
31
31
  /** Additional headers to include in the request. */
32
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
32
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
33
33
  }
34
34
  }
35
35
  export declare class PhonicClient {
@@ -14,8 +14,8 @@ export class PhonicClient {
14
14
  this._options = Object.assign(Object.assign({}, _options), { headers: mergeHeaders({
15
15
  "X-Fern-Language": "JavaScript",
16
16
  "X-Fern-SDK-Name": "phonic",
17
- "X-Fern-SDK-Version": "0.30.10",
18
- "User-Agent": "phonic/0.30.10",
17
+ "X-Fern-SDK-Version": "0.30.11",
18
+ "User-Agent": "phonic/0.30.11",
19
19
  "X-Fern-Runtime": core.RUNTIME.type,
20
20
  "X-Fern-Runtime-Version": core.RUNTIME.version,
21
21
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -11,7 +11,7 @@ export declare namespace Agents {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace Agents {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class Agents {
@@ -52,6 +52,8 @@ export interface AgentsCreateRequest {
52
52
  audio_speed?: number;
53
53
  /** The background noise level of the agent. */
54
54
  background_noise_level?: number;
55
+ /** The background noise type. Can be "office", "call-center", "coffee-shop", or null. */
56
+ background_noise?: Phonic.CreateAgentRequest.BackgroundNoise | null;
55
57
  /** Message to play when the conversation starts. Can contain template variables like `{{customer_name}}`. */
56
58
  welcome_message?: string;
57
59
  /** Instructions for the conversation. Can contain template variables like `{{subject}}`. */
@@ -52,6 +52,8 @@ export interface UpdateAgentRequest {
52
52
  audio_speed?: number;
53
53
  /** The background noise level of the agent. */
54
54
  background_noise_level?: number;
55
+ /** The background noise type. Can be "office", "call-center", "coffee-shop", or null. */
56
+ background_noise?: UpdateAgentRequest.BackgroundNoise | null;
55
57
  /** Message to play when the conversation starts. Can contain template variables like `{{customer_name}}`. */
56
58
  welcome_message?: string;
57
59
  /** Instructions for the conversation. Can contain template variables like `{{subject}}`. */
@@ -86,6 +88,15 @@ export declare namespace UpdateAgentRequest {
86
88
  readonly Pcm8000: "pcm_8000";
87
89
  readonly Mulaw8000: "mulaw_8000";
88
90
  };
91
+ /**
92
+ * The background noise type. Can be "office", "call-center", "coffee-shop", or null.
93
+ */
94
+ type BackgroundNoise = "office" | "call-center" | "coffee-shop";
95
+ const BackgroundNoise: {
96
+ readonly Office: "office";
97
+ readonly CallCenter: "call-center";
98
+ readonly CoffeeShop: "coffee-shop";
99
+ };
89
100
  namespace TemplateVariables {
90
101
  interface Value {
91
102
  default_value: string | null;
@@ -9,4 +9,9 @@ export var UpdateAgentRequest;
9
9
  Pcm8000: "pcm_8000",
10
10
  Mulaw8000: "mulaw_8000",
11
11
  };
12
+ UpdateAgentRequest.BackgroundNoise = {
13
+ Office: "office",
14
+ CallCenter: "call-center",
15
+ CoffeeShop: "coffee-shop",
16
+ };
12
17
  })(UpdateAgentRequest || (UpdateAgentRequest = {}));
@@ -12,7 +12,7 @@ export declare namespace Conversations {
12
12
  baseUrl?: core.Supplier<string>;
13
13
  apiKey?: core.Supplier<core.BearerToken | undefined>;
14
14
  /** Additional headers to include in requests. */
15
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
15
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
16
16
  fetcher?: core.FetchFunction;
17
17
  }
18
18
  interface RequestOptions {
@@ -25,7 +25,7 @@ export declare namespace Conversations {
25
25
  /** Additional query string parameters to include in the request. */
26
26
  queryParams?: Record<string, unknown>;
27
27
  /** Additional headers to include in the request. */
28
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
28
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
29
29
  }
30
30
  interface ConnectArgs {
31
31
  downstream_websocket_url?: string | undefined;
@@ -11,7 +11,7 @@ export declare namespace ExtractionSchemas {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace ExtractionSchemas {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class ExtractionSchemas {
@@ -11,7 +11,7 @@ export declare namespace Projects {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace Projects {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class Projects {
@@ -11,7 +11,7 @@ export declare namespace Tools {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace Tools {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class Tools {
@@ -11,7 +11,7 @@ export declare namespace Voices {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace Voices {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class Voices {
@@ -21,6 +21,8 @@ export interface Agent {
21
21
  audio_speed: number;
22
22
  /** The background noise level of the agent. Must be between 0 and 1. */
23
23
  background_noise_level: number;
24
+ /** The background noise type. Can be "office", "call-center", "coffee-shop", or null. */
25
+ background_noise: Agent.BackgroundNoise | null;
24
26
  /** Message to play when the conversation starts. */
25
27
  welcome_message: string | null;
26
28
  /** Instructions for the conversation. */
@@ -62,6 +64,15 @@ export declare namespace Agent {
62
64
  readonly Pcm8000: "pcm_8000";
63
65
  readonly Mulaw8000: "mulaw_8000";
64
66
  };
67
+ /**
68
+ * The background noise type. Can be "office", "call-center", "coffee-shop", or null.
69
+ */
70
+ type BackgroundNoise = "office" | "call-center" | "coffee-shop";
71
+ const BackgroundNoise: {
72
+ readonly Office: "office";
73
+ readonly CallCenter: "call-center";
74
+ readonly CoffeeShop: "coffee-shop";
75
+ };
65
76
  namespace TemplateVariables {
66
77
  interface Value {
67
78
  default_value: string | null;
@@ -9,4 +9,9 @@ export var Agent;
9
9
  Pcm8000: "pcm_8000",
10
10
  Mulaw8000: "mulaw_8000",
11
11
  };
12
+ Agent.BackgroundNoise = {
13
+ Office: "office",
14
+ CallCenter: "call-center",
15
+ CoffeeShop: "coffee-shop",
16
+ };
12
17
  })(Agent || (Agent = {}));
@@ -15,6 +15,8 @@ export interface ConfigPayload {
15
15
  audio_speed?: number;
16
16
  /** Background noise level for the conversation */
17
17
  background_noise_level?: number;
18
+ /** Background noise type for the conversation */
19
+ background_noise?: ConfigPayload.BackgroundNoise | null;
18
20
  /** Message to play when conversation starts */
19
21
  welcome_message?: string | null;
20
22
  /** Voice ID to use for speech synthesis */
@@ -51,6 +53,15 @@ export interface ConfigPayload {
51
53
  template_variables?: Record<string, string>;
52
54
  }
53
55
  export declare namespace ConfigPayload {
56
+ /**
57
+ * Background noise type for the conversation
58
+ */
59
+ type BackgroundNoise = "office" | "call-center" | "coffee-shop";
60
+ const BackgroundNoise: {
61
+ readonly Office: "office";
62
+ readonly CallCenter: "call-center";
63
+ readonly CoffeeShop: "coffee-shop";
64
+ };
54
65
  /**
55
66
  * Audio input format
56
67
  */
@@ -3,6 +3,11 @@
3
3
  */
4
4
  export var ConfigPayload;
5
5
  (function (ConfigPayload) {
6
+ ConfigPayload.BackgroundNoise = {
7
+ Office: "office",
8
+ CallCenter: "call-center",
9
+ CoffeeShop: "coffee-shop",
10
+ };
6
11
  ConfigPayload.InputFormat = {
7
12
  Pcm44100: "pcm_44100",
8
13
  Pcm16000: "pcm_16000",
@@ -25,6 +25,8 @@ export interface Conversation {
25
25
  output_format: string;
26
26
  /** Background noise level used in the conversation. */
27
27
  background_noise_level: number;
28
+ /** The background noise type used in the conversation. */
29
+ background_noise: Conversation.BackgroundNoise | null;
28
30
  /** Live transcript of the conversation. */
29
31
  live_transcript: string;
30
32
  /** Post-call processed transcript. */
@@ -75,6 +77,15 @@ export declare namespace Conversation {
75
77
  /** The name of the project. */
76
78
  name: string;
77
79
  }
80
+ /**
81
+ * The background noise type used in the conversation.
82
+ */
83
+ type BackgroundNoise = "office" | "call-center" | "coffee-shop";
84
+ const BackgroundNoise: {
85
+ readonly Office: "office";
86
+ readonly CallCenter: "call-center";
87
+ readonly CoffeeShop: "coffee-shop";
88
+ };
78
89
  /**
79
90
  * Who or what ended the conversation.
80
91
  */
@@ -3,6 +3,11 @@
3
3
  */
4
4
  export var Conversation;
5
5
  (function (Conversation) {
6
+ Conversation.BackgroundNoise = {
7
+ Office: "office",
8
+ CallCenter: "call-center",
9
+ CoffeeShop: "coffee-shop",
10
+ };
6
11
  Conversation.EndedBy = {
7
12
  User: "user",
8
13
  UserCanceled: "user_canceled",
@@ -16,6 +16,8 @@ export interface CreateAgentRequest {
16
16
  audio_speed?: number;
17
17
  /** The background noise level of the agent. */
18
18
  background_noise_level?: number;
19
+ /** The background noise type. Can be "office", "call-center", "coffee-shop", or null. */
20
+ background_noise?: CreateAgentRequest.BackgroundNoise | null;
19
21
  /** Message to play when the conversation starts. Can contain template variables like `{{customer_name}}`. */
20
22
  welcome_message?: string;
21
23
  /** Instructions for the conversation. Can contain template variables like `{{subject}}`. */
@@ -50,6 +52,15 @@ export declare namespace CreateAgentRequest {
50
52
  readonly Pcm8000: "pcm_8000";
51
53
  readonly Mulaw8000: "mulaw_8000";
52
54
  };
55
+ /**
56
+ * The background noise type. Can be "office", "call-center", "coffee-shop", or null.
57
+ */
58
+ type BackgroundNoise = "office" | "call-center" | "coffee-shop";
59
+ const BackgroundNoise: {
60
+ readonly Office: "office";
61
+ readonly CallCenter: "call-center";
62
+ readonly CoffeeShop: "coffee-shop";
63
+ };
53
64
  namespace TemplateVariables {
54
65
  interface Value {
55
66
  default_value: string | null;
@@ -9,4 +9,9 @@ export var CreateAgentRequest;
9
9
  Pcm8000: "pcm_8000",
10
10
  Mulaw8000: "mulaw_8000",
11
11
  };
12
+ CreateAgentRequest.BackgroundNoise = {
13
+ Office: "office",
14
+ CallCenter: "call-center",
15
+ CoffeeShop: "coffee-shop",
16
+ };
12
17
  })(CreateAgentRequest || (CreateAgentRequest = {}));
@@ -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 addJitter(delay) {
15
- // Generate a random value between -JITTER_FACTOR and +JITTER_FACTOR
16
- const jitterMultiplier = 1 + (Math.random() * 2 - 1) * JITTER_FACTOR;
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
- // Calculate base delay using exponential backoff (in milliseconds)
25
- const baseDelay = Math.min(INITIAL_RETRY_DELAY * Math.pow(2, i), MAX_RETRY_DELAY);
26
- // Add jitter to the delay
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>>;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.30.10";
1
+ export declare const SDK_VERSION = "0.30.11";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.30.10";
1
+ export const SDK_VERSION = "0.30.11";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phonic",
3
- "version": "0.30.10",
3
+ "version": "0.30.11",
4
4
  "private": false,
5
5
  "repository": "github:Phonic-Co/phonic-node",
6
6
  "type": "commonjs",