phonic 0.31.6 → 0.31.8
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 +34 -11
- package/dist/cjs/BaseClient.js +2 -2
- package/dist/cjs/Client.d.ts +12 -0
- package/dist/cjs/Client.js +74 -0
- package/dist/cjs/api/resources/conversations/client/Client.d.ts +4 -1
- package/dist/cjs/api/resources/conversations/client/Client.js +18 -11
- package/dist/cjs/api/resources/conversations/client/Socket.d.ts +4 -3
- package/dist/cjs/api/resources/conversations/client/Socket.js +6 -2
- package/dist/cjs/api/resources/conversations/client/requests/ConversationsGetRequest.d.ts +9 -0
- package/dist/cjs/api/resources/conversations/client/requests/ConversationsGetRequest.js +3 -0
- package/dist/cjs/api/resources/conversations/client/requests/ConversationsListRequest.d.ts +3 -0
- package/dist/cjs/api/resources/conversations/client/requests/index.d.ts +1 -0
- package/dist/cjs/api/resources/conversations/exports.d.ts +1 -0
- package/dist/cjs/api/resources/conversations/exports.js +3 -1
- package/dist/cjs/api/resources/conversations/types/ConversationsGetRequestAudioContainer.d.ts +5 -0
- package/dist/cjs/api/resources/conversations/types/ConversationsGetRequestAudioContainer.js +8 -0
- package/dist/cjs/api/resources/conversations/types/ConversationsListRequestAudioContainer.d.ts +5 -0
- package/dist/cjs/api/resources/conversations/types/ConversationsListRequestAudioContainer.js +8 -0
- package/dist/cjs/api/resources/conversations/types/index.d.ts +2 -0
- package/dist/cjs/api/resources/conversations/types/index.js +2 -0
- package/dist/cjs/api/types/SayPayload.d.ts +7 -0
- package/dist/cjs/api/types/SayPayload.js +3 -0
- package/dist/cjs/api/types/index.d.ts +1 -0
- package/dist/cjs/api/types/index.js +1 -0
- package/dist/cjs/core/fetcher/BinaryResponse.d.ts +1 -1
- package/dist/cjs/core/fetcher/index.d.ts +2 -0
- package/dist/cjs/core/fetcher/index.js +3 -1
- package/dist/cjs/core/fetcher/makePassthroughRequest.d.ts +49 -0
- package/dist/cjs/core/fetcher/makePassthroughRequest.js +135 -0
- package/dist/cjs/core/websocket/ws.d.ts +10 -1
- package/dist/cjs/core/websocket/ws.js +17 -5
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.mjs +2 -2
- package/dist/esm/Client.d.mts +12 -0
- package/dist/esm/Client.mjs +41 -0
- package/dist/esm/api/resources/conversations/client/Client.d.mts +4 -1
- package/dist/esm/api/resources/conversations/client/Client.mjs +18 -11
- package/dist/esm/api/resources/conversations/client/Socket.d.mts +4 -3
- package/dist/esm/api/resources/conversations/client/Socket.mjs +6 -2
- package/dist/esm/api/resources/conversations/client/requests/ConversationsGetRequest.d.mts +9 -0
- package/dist/esm/api/resources/conversations/client/requests/ConversationsGetRequest.mjs +2 -0
- package/dist/esm/api/resources/conversations/client/requests/ConversationsListRequest.d.mts +3 -0
- package/dist/esm/api/resources/conversations/client/requests/index.d.mts +1 -0
- package/dist/esm/api/resources/conversations/exports.d.mts +1 -0
- package/dist/esm/api/resources/conversations/exports.mjs +1 -0
- package/dist/esm/api/resources/conversations/types/ConversationsGetRequestAudioContainer.d.mts +5 -0
- package/dist/esm/api/resources/conversations/types/ConversationsGetRequestAudioContainer.mjs +5 -0
- package/dist/esm/api/resources/conversations/types/ConversationsListRequestAudioContainer.d.mts +5 -0
- package/dist/esm/api/resources/conversations/types/ConversationsListRequestAudioContainer.mjs +5 -0
- package/dist/esm/api/resources/conversations/types/index.d.mts +2 -0
- package/dist/esm/api/resources/conversations/types/index.mjs +2 -0
- package/dist/esm/api/types/SayPayload.d.mts +7 -0
- package/dist/esm/api/types/SayPayload.mjs +2 -0
- package/dist/esm/api/types/index.d.mts +1 -0
- package/dist/esm/api/types/index.mjs +1 -0
- package/dist/esm/core/fetcher/BinaryResponse.d.mts +1 -1
- package/dist/esm/core/fetcher/index.d.mts +2 -0
- package/dist/esm/core/fetcher/index.mjs +1 -0
- package/dist/esm/core/fetcher/makePassthroughRequest.d.mts +49 -0
- package/dist/esm/core/fetcher/makePassthroughRequest.mjs +132 -0
- package/dist/esm/core/websocket/ws.d.mts +10 -1
- package/dist/esm/core/websocket/ws.mjs +17 -5
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +7 -7
- package/reference.md +9 -1
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.makePassthroughRequest = makePassthroughRequest;
|
|
13
|
+
const logger_js_1 = require("../logging/logger.js");
|
|
14
|
+
const join_js_1 = require("../url/join.js");
|
|
15
|
+
const EndpointSupplier_js_1 = require("./EndpointSupplier.js");
|
|
16
|
+
const getFetchFn_js_1 = require("./getFetchFn.js");
|
|
17
|
+
const makeRequest_js_1 = require("./makeRequest.js");
|
|
18
|
+
const requestWithRetries_js_1 = require("./requestWithRetries.js");
|
|
19
|
+
const Supplier_js_1 = require("./Supplier.js");
|
|
20
|
+
/**
|
|
21
|
+
* Makes a passthrough HTTP request using the SDK's configuration (auth, retry, logging, etc.)
|
|
22
|
+
* while mimicking the standard `fetch` API.
|
|
23
|
+
*
|
|
24
|
+
* @param input - The URL, path, or Request object. If a relative path, it will be resolved against the configured base URL.
|
|
25
|
+
* @param init - Standard RequestInit options (method, headers, body, signal, etc.)
|
|
26
|
+
* @param clientOptions - SDK client options (auth, default headers, logging, etc.)
|
|
27
|
+
* @param requestOptions - Per-request overrides (timeout, retries, extra headers, abort signal).
|
|
28
|
+
* @returns A standard Response object.
|
|
29
|
+
*/
|
|
30
|
+
function makePassthroughRequest(input, init, clientOptions, requestOptions) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
33
|
+
const logger = (0, logger_js_1.createLogger)(clientOptions.logging);
|
|
34
|
+
// Extract URL and default init properties from Request object if provided
|
|
35
|
+
let url;
|
|
36
|
+
let effectiveInit = init;
|
|
37
|
+
if (input instanceof Request) {
|
|
38
|
+
url = input.url;
|
|
39
|
+
// If no explicit init provided, extract properties from the Request object
|
|
40
|
+
if (init == null) {
|
|
41
|
+
effectiveInit = {
|
|
42
|
+
method: input.method,
|
|
43
|
+
headers: Object.fromEntries(input.headers.entries()),
|
|
44
|
+
body: input.body,
|
|
45
|
+
signal: input.signal,
|
|
46
|
+
credentials: input.credentials,
|
|
47
|
+
cache: input.cache,
|
|
48
|
+
redirect: input.redirect,
|
|
49
|
+
referrer: input.referrer,
|
|
50
|
+
integrity: input.integrity,
|
|
51
|
+
mode: input.mode,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
url = input instanceof URL ? input.toString() : input;
|
|
57
|
+
}
|
|
58
|
+
// Resolve the base URL
|
|
59
|
+
const baseUrl = (_a = (clientOptions.baseUrl != null ? yield Supplier_js_1.Supplier.get(clientOptions.baseUrl) : undefined)) !== null && _a !== void 0 ? _a : (clientOptions.environment != null ? yield Supplier_js_1.Supplier.get(clientOptions.environment) : undefined);
|
|
60
|
+
// Determine the full URL
|
|
61
|
+
let fullUrl;
|
|
62
|
+
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
63
|
+
fullUrl = url;
|
|
64
|
+
}
|
|
65
|
+
else if (baseUrl != null) {
|
|
66
|
+
fullUrl = (0, join_js_1.join)(baseUrl, url);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
fullUrl = url;
|
|
70
|
+
}
|
|
71
|
+
// Merge headers: SDK default headers -> auth headers -> user-provided headers
|
|
72
|
+
const mergedHeaders = {};
|
|
73
|
+
// Apply SDK default headers (resolve suppliers)
|
|
74
|
+
if (clientOptions.headers != null) {
|
|
75
|
+
for (const [key, value] of Object.entries(clientOptions.headers)) {
|
|
76
|
+
const resolved = yield EndpointSupplier_js_1.EndpointSupplier.get(value, { endpointMetadata: {} });
|
|
77
|
+
if (resolved != null) {
|
|
78
|
+
mergedHeaders[key.toLowerCase()] = `${resolved}`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Apply auth headers
|
|
83
|
+
if (clientOptions.getAuthHeaders != null) {
|
|
84
|
+
const authHeaders = yield clientOptions.getAuthHeaders();
|
|
85
|
+
for (const [key, value] of Object.entries(authHeaders)) {
|
|
86
|
+
mergedHeaders[key.toLowerCase()] = value;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Apply user-provided headers from init
|
|
90
|
+
if ((effectiveInit === null || effectiveInit === void 0 ? void 0 : effectiveInit.headers) != null) {
|
|
91
|
+
const initHeaders = effectiveInit.headers instanceof Headers
|
|
92
|
+
? Object.fromEntries(effectiveInit.headers.entries())
|
|
93
|
+
: Array.isArray(effectiveInit.headers)
|
|
94
|
+
? Object.fromEntries(effectiveInit.headers)
|
|
95
|
+
: effectiveInit.headers;
|
|
96
|
+
for (const [key, value] of Object.entries(initHeaders)) {
|
|
97
|
+
if (value != null) {
|
|
98
|
+
mergedHeaders[key.toLowerCase()] = value;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Apply per-request option headers (highest priority)
|
|
103
|
+
if ((requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers) != null) {
|
|
104
|
+
for (const [key, value] of Object.entries(requestOptions.headers)) {
|
|
105
|
+
mergedHeaders[key.toLowerCase()] = value;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const method = (_b = effectiveInit === null || effectiveInit === void 0 ? void 0 : effectiveInit.method) !== null && _b !== void 0 ? _b : "GET";
|
|
109
|
+
const body = effectiveInit === null || effectiveInit === void 0 ? void 0 : effectiveInit.body;
|
|
110
|
+
const timeoutInSeconds = (_c = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _c !== void 0 ? _c : clientOptions.timeoutInSeconds;
|
|
111
|
+
const timeoutMs = timeoutInSeconds != null ? timeoutInSeconds * 1000 : undefined;
|
|
112
|
+
const maxRetries = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _d !== void 0 ? _d : clientOptions.maxRetries;
|
|
113
|
+
const abortSignal = (_f = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal) !== null && _e !== void 0 ? _e : effectiveInit === null || effectiveInit === void 0 ? void 0 : effectiveInit.signal) !== null && _f !== void 0 ? _f : undefined;
|
|
114
|
+
const fetchFn = (_g = clientOptions.fetch) !== null && _g !== void 0 ? _g : (yield (0, getFetchFn_js_1.getFetchFn)());
|
|
115
|
+
if (logger.isDebug()) {
|
|
116
|
+
logger.debug("Making passthrough HTTP request", {
|
|
117
|
+
method,
|
|
118
|
+
url: fullUrl,
|
|
119
|
+
hasBody: body != null,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const response = yield (0, requestWithRetries_js_1.requestWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
return (0, makeRequest_js_1.makeRequest)(fetchFn, fullUrl, method, mergedHeaders, body !== null && body !== void 0 ? body : undefined, timeoutMs, abortSignal, (effectiveInit === null || effectiveInit === void 0 ? void 0 : effectiveInit.credentials) === "include", undefined, // duplex
|
|
124
|
+
false);
|
|
125
|
+
}), maxRetries);
|
|
126
|
+
if (logger.isDebug()) {
|
|
127
|
+
logger.debug("Passthrough HTTP request completed", {
|
|
128
|
+
method,
|
|
129
|
+
url: fullUrl,
|
|
130
|
+
statusCode: response.status,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return response;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
@@ -85,7 +85,7 @@ export declare class ReconnectingWebSocket {
|
|
|
85
85
|
/**
|
|
86
86
|
* The current state of the connection; this is one of the Ready state constants
|
|
87
87
|
*/
|
|
88
|
-
get readyState():
|
|
88
|
+
get readyState(): ReconnectingWebSocket.ReadyState;
|
|
89
89
|
/**
|
|
90
90
|
* The URL as resolved by the constructor
|
|
91
91
|
*/
|
|
@@ -148,3 +148,12 @@ export declare class ReconnectingWebSocket {
|
|
|
148
148
|
private _addListeners;
|
|
149
149
|
private _clearTimeouts;
|
|
150
150
|
}
|
|
151
|
+
export declare namespace ReconnectingWebSocket {
|
|
152
|
+
const ReadyState: {
|
|
153
|
+
readonly CONNECTING: 0;
|
|
154
|
+
readonly OPEN: 1;
|
|
155
|
+
readonly CLOSING: 2;
|
|
156
|
+
readonly CLOSED: 3;
|
|
157
|
+
};
|
|
158
|
+
type ReadyState = (typeof ReadyState)[keyof typeof ReadyState];
|
|
159
|
+
}
|
|
@@ -39,13 +39,13 @@ const index_js_1 = require("../runtime/index.js");
|
|
|
39
39
|
const qs_js_1 = require("../url/qs.js");
|
|
40
40
|
const Events = __importStar(require("./events.js"));
|
|
41
41
|
const getGlobalWebSocket = () => {
|
|
42
|
-
if (
|
|
42
|
+
if (index_js_1.RUNTIME.type === "node" || index_js_1.RUNTIME.type === "bun" || index_js_1.RUNTIME.type === "deno") {
|
|
43
|
+
return ws_1.WebSocket;
|
|
44
|
+
}
|
|
45
|
+
else if (typeof WebSocket !== "undefined") {
|
|
43
46
|
// @ts-ignore
|
|
44
47
|
return WebSocket;
|
|
45
48
|
}
|
|
46
|
-
else if (index_js_1.RUNTIME.type === "node") {
|
|
47
|
-
return ws_1.WebSocket;
|
|
48
|
-
}
|
|
49
49
|
return undefined;
|
|
50
50
|
};
|
|
51
51
|
/**
|
|
@@ -108,6 +108,7 @@ class ReconnectingWebSocket {
|
|
|
108
108
|
this._clearTimeouts();
|
|
109
109
|
if (this._ws) {
|
|
110
110
|
this._removeListeners();
|
|
111
|
+
// Absorb async errors emitted by ws when closing during CONNECTING state
|
|
111
112
|
this._ws.addEventListener("error", () => { });
|
|
112
113
|
try {
|
|
113
114
|
this._ws.close(1000, "aborted");
|
|
@@ -235,7 +236,9 @@ class ReconnectingWebSocket {
|
|
|
235
236
|
if (this._ws) {
|
|
236
237
|
return this._ws.readyState;
|
|
237
238
|
}
|
|
238
|
-
return this._options.startClosed
|
|
239
|
+
return this._options.startClosed
|
|
240
|
+
? ReconnectingWebSocket.ReadyState.CLOSED
|
|
241
|
+
: ReconnectingWebSocket.ReadyState.CONNECTING;
|
|
239
242
|
}
|
|
240
243
|
/**
|
|
241
244
|
* The URL as resolved by the constructor
|
|
@@ -419,6 +422,7 @@ class ReconnectingWebSocket {
|
|
|
419
422
|
return;
|
|
420
423
|
}
|
|
421
424
|
this._removeListeners();
|
|
425
|
+
// Absorb async errors emitted by ws when closing during CONNECTING state
|
|
422
426
|
this._ws.addEventListener("error", () => { });
|
|
423
427
|
try {
|
|
424
428
|
this._ws.close(code, reason);
|
|
@@ -474,3 +478,11 @@ ReconnectingWebSocket.CONNECTING = 0;
|
|
|
474
478
|
ReconnectingWebSocket.OPEN = 1;
|
|
475
479
|
ReconnectingWebSocket.CLOSING = 2;
|
|
476
480
|
ReconnectingWebSocket.CLOSED = 3;
|
|
481
|
+
(function (ReconnectingWebSocket) {
|
|
482
|
+
ReconnectingWebSocket.ReadyState = {
|
|
483
|
+
CONNECTING: 0,
|
|
484
|
+
OPEN: 1,
|
|
485
|
+
CLOSING: 2,
|
|
486
|
+
CLOSED: 3,
|
|
487
|
+
};
|
|
488
|
+
})(ReconnectingWebSocket || (exports.ReconnectingWebSocket = ReconnectingWebSocket = {}));
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.31.
|
|
1
|
+
export declare const SDK_VERSION = "0.31.8";
|
package/dist/cjs/version.js
CHANGED
package/dist/esm/BaseClient.mjs
CHANGED
|
@@ -6,8 +6,8 @@ export function normalizeClientOptions(options) {
|
|
|
6
6
|
const headers = mergeHeaders({
|
|
7
7
|
"X-Fern-Language": "JavaScript",
|
|
8
8
|
"X-Fern-SDK-Name": "phonic",
|
|
9
|
-
"X-Fern-SDK-Version": "0.31.
|
|
10
|
-
"User-Agent": "phonic/0.31.
|
|
9
|
+
"X-Fern-SDK-Version": "0.31.8",
|
|
10
|
+
"User-Agent": "phonic/0.31.8",
|
|
11
11
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
12
12
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
13
13
|
}, options === null || options === void 0 ? void 0 : options.headers);
|
package/dist/esm/Client.d.mts
CHANGED
|
@@ -7,6 +7,7 @@ import { ToolsClient } from "./api/resources/tools/client/Client.mjs";
|
|
|
7
7
|
import { VoicesClient } from "./api/resources/voices/client/Client.mjs";
|
|
8
8
|
import type { BaseClientOptions, BaseRequestOptions } from "./BaseClient.mjs";
|
|
9
9
|
import { type NormalizedClientOptionsWithAuth } from "./BaseClient.mjs";
|
|
10
|
+
import * as core from "./core/index.mjs";
|
|
10
11
|
export declare namespace PhonicClient {
|
|
11
12
|
type Options = BaseClientOptions;
|
|
12
13
|
interface RequestOptions extends BaseRequestOptions {
|
|
@@ -29,4 +30,15 @@ export declare class PhonicClient {
|
|
|
29
30
|
get conversations(): ConversationsClient;
|
|
30
31
|
get auth(): AuthClient;
|
|
31
32
|
get projects(): ProjectsClient;
|
|
33
|
+
/**
|
|
34
|
+
* Make a passthrough request using the SDK's configured auth, retry, logging, etc.
|
|
35
|
+
* This is useful for making requests to endpoints not yet supported in the SDK.
|
|
36
|
+
* The input can be a URL string, URL object, or Request object. Relative paths are resolved against the configured base URL.
|
|
37
|
+
*
|
|
38
|
+
* @param {Request | string | URL} input - The URL, path, or Request object.
|
|
39
|
+
* @param {RequestInit} init - Standard fetch RequestInit options.
|
|
40
|
+
* @param {core.PassthroughRequest.RequestOptions} requestOptions - Per-request overrides (timeout, retries, headers, abort signal).
|
|
41
|
+
* @returns {Promise<Response>} A standard Response object.
|
|
42
|
+
*/
|
|
43
|
+
fetch(input: Request | string | URL, init?: RequestInit, requestOptions?: core.PassthroughRequest.RequestOptions): Promise<Response>;
|
|
32
44
|
}
|
package/dist/esm/Client.mjs
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
// This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
import { AgentsClient } from "./api/resources/agents/client/Client.mjs";
|
|
3
12
|
import { AuthClient } from "./api/resources/auth/client/Client.mjs";
|
|
4
13
|
import { ConversationsClient } from "./api/resources/conversations/client/Client.mjs";
|
|
@@ -7,6 +16,8 @@ import { ProjectsClient } from "./api/resources/projects/client/Client.mjs";
|
|
|
7
16
|
import { ToolsClient } from "./api/resources/tools/client/Client.mjs";
|
|
8
17
|
import { VoicesClient } from "./api/resources/voices/client/Client.mjs";
|
|
9
18
|
import { normalizeClientOptionsWithAuth } from "./BaseClient.mjs";
|
|
19
|
+
import * as core from "./core/index.mjs";
|
|
20
|
+
import * as environments from "./environments.mjs";
|
|
10
21
|
export class PhonicClient {
|
|
11
22
|
constructor(options = {}) {
|
|
12
23
|
this._options = normalizeClientOptionsWithAuth(options);
|
|
@@ -39,4 +50,34 @@ export class PhonicClient {
|
|
|
39
50
|
var _a;
|
|
40
51
|
return ((_a = this._projects) !== null && _a !== void 0 ? _a : (this._projects = new ProjectsClient(this._options)));
|
|
41
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Make a passthrough request using the SDK's configured auth, retry, logging, etc.
|
|
55
|
+
* This is useful for making requests to endpoints not yet supported in the SDK.
|
|
56
|
+
* The input can be a URL string, URL object, or Request object. Relative paths are resolved against the configured base URL.
|
|
57
|
+
*
|
|
58
|
+
* @param {Request | string | URL} input - The URL, path, or Request object.
|
|
59
|
+
* @param {RequestInit} init - Standard fetch RequestInit options.
|
|
60
|
+
* @param {core.PassthroughRequest.RequestOptions} requestOptions - Per-request overrides (timeout, retries, headers, abort signal).
|
|
61
|
+
* @returns {Promise<Response>} A standard Response object.
|
|
62
|
+
*/
|
|
63
|
+
fetch(input, init, requestOptions) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
var _a;
|
|
66
|
+
return core.makePassthroughRequest(input, init, {
|
|
67
|
+
baseUrl: (_a = this._options.baseUrl) !== null && _a !== void 0 ? _a : (() => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
var _a;
|
|
69
|
+
const env = yield core.Supplier.get(this._options.environment);
|
|
70
|
+
return typeof env === "string"
|
|
71
|
+
? env
|
|
72
|
+
: ((_a = env === null || env === void 0 ? void 0 : env.base) !== null && _a !== void 0 ? _a : environments.PhonicEnvironment.Default.base);
|
|
73
|
+
})),
|
|
74
|
+
headers: this._options.headers,
|
|
75
|
+
timeoutInSeconds: this._options.timeoutInSeconds,
|
|
76
|
+
maxRetries: this._options.maxRetries,
|
|
77
|
+
fetch: this._options.fetch,
|
|
78
|
+
logging: this._options.logging,
|
|
79
|
+
getAuthHeaders: () => __awaiter(this, void 0, void 0, function* () { return (yield this._options.authProvider.getAuthRequest()).headers; }),
|
|
80
|
+
}, requestOptions);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
42
83
|
}
|
|
@@ -9,6 +9,8 @@ export declare namespace ConversationsClient {
|
|
|
9
9
|
}
|
|
10
10
|
interface ConnectArgs {
|
|
11
11
|
downstream_websocket_url?: string;
|
|
12
|
+
/** WebSocket subprotocols to use for the connection. */
|
|
13
|
+
protocols?: string | string[];
|
|
12
14
|
/** Additional query parameters to send with the websocket connect request. */
|
|
13
15
|
queryParams?: Record<string, unknown>;
|
|
14
16
|
/** Arbitrary headers to send with the websocket connect request. */
|
|
@@ -47,6 +49,7 @@ export declare class ConversationsClient {
|
|
|
47
49
|
* Returns a conversation by ID.
|
|
48
50
|
*
|
|
49
51
|
* @param {string} id - The ID of the conversation to get.
|
|
52
|
+
* @param {Phonic.ConversationsGetRequest} request
|
|
50
53
|
* @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
|
|
51
54
|
*
|
|
52
55
|
* @throws {@link Phonic.UnauthorizedError}
|
|
@@ -57,7 +60,7 @@ export declare class ConversationsClient {
|
|
|
57
60
|
* @example
|
|
58
61
|
* await client.conversations.get("id")
|
|
59
62
|
*/
|
|
60
|
-
get(id: string, requestOptions?: ConversationsClient.RequestOptions): core.HttpResponsePromise<Phonic.ConversationsGetResponse>;
|
|
63
|
+
get(id: string, request?: Phonic.ConversationsGetRequest, requestOptions?: ConversationsClient.RequestOptions): core.HttpResponsePromise<Phonic.ConversationsGetResponse>;
|
|
61
64
|
private __get;
|
|
62
65
|
/**
|
|
63
66
|
* Cancels an active conversation.
|
|
@@ -52,7 +52,7 @@ export class ConversationsClient {
|
|
|
52
52
|
__list() {
|
|
53
53
|
return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
|
|
54
54
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
55
|
-
const { project, external_id: externalId, duration_min: durationMin, duration_max: durationMax, started_at_min: startedAtMin, started_at_max: startedAtMax, before, after, limit, } = request;
|
|
55
|
+
const { project, external_id: externalId, duration_min: durationMin, duration_max: durationMax, started_at_min: startedAtMin, started_at_max: startedAtMax, before, after, limit, audio_container: audioContainer, } = request;
|
|
56
56
|
const _queryParams = {
|
|
57
57
|
project,
|
|
58
58
|
external_id: externalId,
|
|
@@ -63,6 +63,7 @@ export class ConversationsClient {
|
|
|
63
63
|
before,
|
|
64
64
|
after,
|
|
65
65
|
limit,
|
|
66
|
+
audio_container: audioContainer != null ? audioContainer : undefined,
|
|
66
67
|
};
|
|
67
68
|
const _authRequest = yield this._options.authProvider.getAuthRequest();
|
|
68
69
|
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
@@ -108,6 +109,7 @@ export class ConversationsClient {
|
|
|
108
109
|
* Returns a conversation by ID.
|
|
109
110
|
*
|
|
110
111
|
* @param {string} id - The ID of the conversation to get.
|
|
112
|
+
* @param {Phonic.ConversationsGetRequest} request
|
|
111
113
|
* @param {ConversationsClient.RequestOptions} requestOptions - Request-specific configuration.
|
|
112
114
|
*
|
|
113
115
|
* @throws {@link Phonic.UnauthorizedError}
|
|
@@ -118,12 +120,16 @@ export class ConversationsClient {
|
|
|
118
120
|
* @example
|
|
119
121
|
* await client.conversations.get("id")
|
|
120
122
|
*/
|
|
121
|
-
get(id, requestOptions) {
|
|
122
|
-
return core.HttpResponsePromise.fromPromise(this.__get(id, requestOptions));
|
|
123
|
+
get(id, request = {}, requestOptions) {
|
|
124
|
+
return core.HttpResponsePromise.fromPromise(this.__get(id, request, requestOptions));
|
|
123
125
|
}
|
|
124
|
-
__get(
|
|
125
|
-
return __awaiter(this,
|
|
126
|
+
__get(id_1) {
|
|
127
|
+
return __awaiter(this, arguments, void 0, function* (id, request = {}, requestOptions) {
|
|
126
128
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
129
|
+
const { audio_container: audioContainer } = request;
|
|
130
|
+
const _queryParams = {
|
|
131
|
+
audio_container: audioContainer != null ? audioContainer : undefined,
|
|
132
|
+
};
|
|
127
133
|
const _authRequest = yield this._options.authProvider.getAuthRequest();
|
|
128
134
|
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
129
135
|
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
|
|
@@ -131,7 +137,7 @@ export class ConversationsClient {
|
|
|
131
137
|
.base, `conversations/${core.url.encodePathParam(id)}`),
|
|
132
138
|
method: "GET",
|
|
133
139
|
headers: _headers,
|
|
134
|
-
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
|
|
140
|
+
queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
|
|
135
141
|
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
|
|
136
142
|
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
|
|
137
143
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
@@ -703,16 +709,17 @@ export class ConversationsClient {
|
|
|
703
709
|
}
|
|
704
710
|
connect() {
|
|
705
711
|
return __awaiter(this, arguments, void 0, function* (args = {}) {
|
|
706
|
-
var _a, _b;
|
|
707
|
-
const { downstream_websocket_url: downstreamWebsocketUrl, queryParams, headers, debug, reconnectAttempts, connectionTimeoutInSeconds, abortSignal, } = args;
|
|
712
|
+
var _a, _b, _c, _d, _e;
|
|
713
|
+
const { downstream_websocket_url: downstreamWebsocketUrl, protocols, queryParams, headers, debug, reconnectAttempts, connectionTimeoutInSeconds, abortSignal, } = args;
|
|
708
714
|
const _queryParams = {
|
|
709
715
|
downstream_websocket_url: downstreamWebsocketUrl,
|
|
710
716
|
};
|
|
711
|
-
const
|
|
717
|
+
const _authRequest = yield this._options.authProvider.getAuthRequest();
|
|
718
|
+
const _headers = Object.assign(Object.assign(Object.assign({}, ((_a = _authRequest.headers) !== null && _a !== void 0 ? _a : {})), ((_c = (_b = this._options) === null || _b === void 0 ? void 0 : _b.headers) !== null && _c !== void 0 ? _c : {})), headers);
|
|
712
719
|
const socket = new core.ReconnectingWebSocket({
|
|
713
|
-
url: core.url.join((
|
|
720
|
+
url: core.url.join((_d = (yield core.Supplier.get(this._options.baseUrl))) !== null && _d !== void 0 ? _d : ((_e = (yield core.Supplier.get(this._options.environment))) !== null && _e !== void 0 ? _e : environments.PhonicEnvironment.Default)
|
|
714
721
|
.production, "/v1/sts/ws"),
|
|
715
|
-
protocols: [],
|
|
722
|
+
protocols: protocols !== null && protocols !== void 0 ? protocols : [],
|
|
716
723
|
queryParameters: Object.assign(Object.assign({}, _queryParams), queryParams),
|
|
717
724
|
headers: _headers,
|
|
718
725
|
options: {
|
|
@@ -21,7 +21,7 @@ export declare class ConversationsSocket {
|
|
|
21
21
|
private handleError;
|
|
22
22
|
constructor(args: ConversationsSocket.Args);
|
|
23
23
|
/** The current state of the connection; this is one of the readyState constants. */
|
|
24
|
-
get readyState():
|
|
24
|
+
get readyState(): core.ReconnectingWebSocket.ReadyState;
|
|
25
25
|
/**
|
|
26
26
|
* @param event - The event to attach to.
|
|
27
27
|
* @param callback - The callback to run when the event is triggered.
|
|
@@ -40,6 +40,7 @@ export declare class ConversationsSocket {
|
|
|
40
40
|
sendSetExternalId(message: Phonic.SetExternalIdPayload): void;
|
|
41
41
|
sendToolCallOutput(message: Phonic.ToolCallOutputPayload): void;
|
|
42
42
|
sendGenerateReply(message: Phonic.GenerateReplyPayload): void;
|
|
43
|
+
sendSay(message: Phonic.SayPayload): void;
|
|
43
44
|
/** Connect to the websocket and register event handlers. */
|
|
44
45
|
connect(): ConversationsSocket;
|
|
45
46
|
/** Close the websocket and unregister event handlers. */
|
|
@@ -49,7 +50,7 @@ export declare class ConversationsSocket {
|
|
|
49
50
|
/** Asserts that the websocket is open. */
|
|
50
51
|
private assertSocketIsOpen;
|
|
51
52
|
/** Send a binary payload to the websocket. */
|
|
52
|
-
protected sendBinary(payload:
|
|
53
|
+
protected sendBinary(payload: ArrayBuffer | Blob | ArrayBufferView): void;
|
|
53
54
|
/** Send a JSON payload to the websocket. */
|
|
54
|
-
protected sendJson(payload: Phonic.ConfigPayload | Phonic.AudioChunkPayload | Phonic.UpdateSystemPromptPayload | Phonic.AddSystemMessagePayload | Phonic.SetExternalIdPayload | Phonic.ToolCallOutputPayload | Phonic.GenerateReplyPayload): void;
|
|
55
|
+
protected sendJson(payload: Phonic.ConfigPayload | Phonic.AudioChunkPayload | Phonic.UpdateSystemPromptPayload | Phonic.AddSystemMessagePayload | Phonic.SetExternalIdPayload | Phonic.ToolCallOutputPayload | Phonic.GenerateReplyPayload | Phonic.SayPayload): void;
|
|
55
56
|
}
|
|
@@ -82,6 +82,10 @@ export class ConversationsSocket {
|
|
|
82
82
|
this.assertSocketIsOpen();
|
|
83
83
|
this.sendJson(message);
|
|
84
84
|
}
|
|
85
|
+
sendSay(message) {
|
|
86
|
+
this.assertSocketIsOpen();
|
|
87
|
+
this.sendJson(message);
|
|
88
|
+
}
|
|
85
89
|
/** Connect to the websocket and register event handlers. */
|
|
86
90
|
connect() {
|
|
87
91
|
this.socket.reconnect();
|
|
@@ -103,7 +107,7 @@ export class ConversationsSocket {
|
|
|
103
107
|
/** Returns a promise that resolves when the websocket is open. */
|
|
104
108
|
waitForOpen() {
|
|
105
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
if (this.socket.readyState === core.ReconnectingWebSocket.OPEN) {
|
|
110
|
+
if (this.socket.readyState === core.ReconnectingWebSocket.ReadyState.OPEN) {
|
|
107
111
|
return this.socket;
|
|
108
112
|
}
|
|
109
113
|
return new Promise((resolve, reject) => {
|
|
@@ -121,7 +125,7 @@ export class ConversationsSocket {
|
|
|
121
125
|
if (!this.socket) {
|
|
122
126
|
throw new Error("Socket is not connected.");
|
|
123
127
|
}
|
|
124
|
-
if (this.socket.readyState !== core.ReconnectingWebSocket.OPEN) {
|
|
128
|
+
if (this.socket.readyState !== core.ReconnectingWebSocket.ReadyState.OPEN) {
|
|
125
129
|
throw new Error("Socket is not open.");
|
|
126
130
|
}
|
|
127
131
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type * as Phonic from "../../../../index.mjs";
|
|
1
2
|
/**
|
|
2
3
|
* @example
|
|
3
4
|
* {}
|
|
@@ -21,4 +22,6 @@ export interface ConversationsListRequest {
|
|
|
21
22
|
after?: string;
|
|
22
23
|
/** Maximum number of conversations to return per page. */
|
|
23
24
|
limit?: number;
|
|
25
|
+
/** Format of the presigned `audio_url` in each conversation in the response. */
|
|
26
|
+
audio_container?: Phonic.ConversationsListRequestAudioContainer;
|
|
24
27
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type { ConversationsGetRequest } from "./ConversationsGetRequest.mjs";
|
|
1
2
|
export type { ConversationsListRequest } from "./ConversationsListRequest.mjs";
|
|
2
3
|
export type { ConversationsSipOutboundCallRequest } from "./ConversationsSipOutboundCallRequest.mjs";
|
|
3
4
|
export type { EvaluateConversationRequest } from "./EvaluateConversationRequest.mjs";
|
package/dist/esm/api/resources/conversations/types/ConversationsListRequestAudioContainer.d.mts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const ConversationsListRequestAudioContainer: {
|
|
2
|
+
readonly WavGz: "wav.gz";
|
|
3
|
+
readonly Wav: "wav";
|
|
4
|
+
};
|
|
5
|
+
export type ConversationsListRequestAudioContainer = (typeof ConversationsListRequestAudioContainer)[keyof typeof ConversationsListRequestAudioContainer];
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export * from "./ConversationsCancelResponse.mjs";
|
|
2
2
|
export * from "./ConversationsExtractDataResponse.mjs";
|
|
3
3
|
export * from "./ConversationsGetAnalysisResponse.mjs";
|
|
4
|
+
export * from "./ConversationsGetRequestAudioContainer.mjs";
|
|
4
5
|
export * from "./ConversationsGetResponse.mjs";
|
|
5
6
|
export * from "./ConversationsListEvaluationsResponse.mjs";
|
|
6
7
|
export * from "./ConversationsListExtractionsResponse.mjs";
|
|
8
|
+
export * from "./ConversationsListRequestAudioContainer.mjs";
|
|
7
9
|
export * from "./ConversationsListResponse.mjs";
|
|
8
10
|
export * from "./ConversationsOutboundCallResponse.mjs";
|
|
9
11
|
export * from "./ConversationsSipOutboundCallResponse.mjs";
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export * from "./ConversationsCancelResponse.mjs";
|
|
2
2
|
export * from "./ConversationsExtractDataResponse.mjs";
|
|
3
3
|
export * from "./ConversationsGetAnalysisResponse.mjs";
|
|
4
|
+
export * from "./ConversationsGetRequestAudioContainer.mjs";
|
|
4
5
|
export * from "./ConversationsGetResponse.mjs";
|
|
5
6
|
export * from "./ConversationsListEvaluationsResponse.mjs";
|
|
6
7
|
export * from "./ConversationsListExtractionsResponse.mjs";
|
|
8
|
+
export * from "./ConversationsListRequestAudioContainer.mjs";
|
|
7
9
|
export * from "./ConversationsListResponse.mjs";
|
|
8
10
|
export * from "./ConversationsOutboundCallResponse.mjs";
|
|
9
11
|
export * from "./ConversationsSipOutboundCallResponse.mjs";
|
|
@@ -31,6 +31,7 @@ export * from "./LanguageCode.mjs";
|
|
|
31
31
|
export * from "./OutboundCallConfig.mjs";
|
|
32
32
|
export * from "./Project.mjs";
|
|
33
33
|
export * from "./ReadyToStartConversationPayload.mjs";
|
|
34
|
+
export * from "./SayPayload.mjs";
|
|
34
35
|
export * from "./SetExternalIdPayload.mjs";
|
|
35
36
|
export * from "./Task.mjs";
|
|
36
37
|
export * from "./Tool.mjs";
|
|
@@ -31,6 +31,7 @@ export * from "./LanguageCode.mjs";
|
|
|
31
31
|
export * from "./OutboundCallConfig.mjs";
|
|
32
32
|
export * from "./Project.mjs";
|
|
33
33
|
export * from "./ReadyToStartConversationPayload.mjs";
|
|
34
|
+
export * from "./SayPayload.mjs";
|
|
34
35
|
export * from "./SetExternalIdPayload.mjs";
|
|
35
36
|
export * from "./Task.mjs";
|
|
36
37
|
export * from "./Tool.mjs";
|
|
@@ -14,6 +14,6 @@ export type BinaryResponse = {
|
|
|
14
14
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bytes)
|
|
15
15
|
* Some versions of the Fetch API may not support this method.
|
|
16
16
|
*/
|
|
17
|
-
bytes?():
|
|
17
|
+
bytes?(): Promise<Uint8Array>;
|
|
18
18
|
};
|
|
19
19
|
export declare function getBinaryResponse(response: Response): BinaryResponse;
|
|
@@ -6,6 +6,8 @@ export type { Fetcher, FetchFunction } from "./Fetcher.mjs";
|
|
|
6
6
|
export { fetcher } from "./Fetcher.mjs";
|
|
7
7
|
export { getHeader } from "./getHeader.mjs";
|
|
8
8
|
export { HttpResponsePromise } from "./HttpResponsePromise.mjs";
|
|
9
|
+
export type { PassthroughRequest } from "./makePassthroughRequest.mjs";
|
|
10
|
+
export { makePassthroughRequest } from "./makePassthroughRequest.mjs";
|
|
9
11
|
export type { RawResponse, WithRawResponse } from "./RawResponse.mjs";
|
|
10
12
|
export { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.mjs";
|
|
11
13
|
export { Supplier } from "./Supplier.mjs";
|