@talk2view/sdk 0.12.1 → 0.14.0
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/dist/auth.d.ts +26 -3
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +78 -14
- package/dist/auth.js.map +1 -1
- package/dist/client.d.ts +30 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +67 -16
- package/dist/client.js.map +1 -1
- package/dist/constants.d.ts +15 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +17 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors.d.ts +8 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +9 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +20 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +56 -6
- package/dist/index.js.map +1 -1
- package/dist/react/useT2VAuth.d.ts +2 -2
- package/dist/react/useT2VAuth.d.ts.map +1 -1
- package/dist/react/useT2VAuth.js +1 -1
- package/dist/react/useT2VAuth.js.map +1 -1
- package/dist/streaming.d.ts.map +1 -1
- package/dist/streaming.js +9 -2
- package/dist/streaming.js.map +1 -1
- package/dist/types.d.ts +28 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/components/Composer.d.ts.map +1 -1
- package/dist/ui/components/Composer.js +42 -6
- package/dist/ui/components/Composer.js.map +1 -1
- package/dist/ui/components/MarkdownRenderer.d.ts.map +1 -1
- package/dist/ui/components/MarkdownRenderer.js +12 -0
- package/dist/ui/components/MarkdownRenderer.js.map +1 -1
- package/dist/ui/components/SettingsPanel.js +2 -2
- package/dist/ui/components/SettingsPanel.js.map +1 -1
- package/dist/ui/components/Talk2View.js +8 -5
- package/dist/ui/components/Talk2View.js.map +1 -1
- package/package.json +5 -2
package/dist/auth.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Auth module — login, signup, refresh, logout, auth state management.
|
|
3
3
|
*/
|
|
4
4
|
import type { T2VClient } from './client';
|
|
5
|
-
import type { User } from './types';
|
|
5
|
+
import type { SignupOutcome, User } from './types';
|
|
6
6
|
type AuthStateCallback = (user: User | null) => void;
|
|
7
7
|
export declare class T2VAuth {
|
|
8
8
|
private readonly client;
|
|
@@ -28,9 +28,14 @@ export declare class T2VAuth {
|
|
|
28
28
|
/** True if the current session is an anonymous demo session. */
|
|
29
29
|
isAnonymous(): boolean;
|
|
30
30
|
/**
|
|
31
|
-
* Create a
|
|
31
|
+
* Create a permanent account.
|
|
32
|
+
*
|
|
33
|
+
* From an anonymous session this CONVERTS in place (same user id — history
|
|
34
|
+
* and purchases stay). The server emails a confirmation link; until it is
|
|
35
|
+
* clicked the session remains anonymous and `confirmationRequired` is true.
|
|
36
|
+
* A 409 means the email already has an account → we sign into it instead.
|
|
32
37
|
*/
|
|
33
|
-
signup(email: string, password: string): Promise<
|
|
38
|
+
signup(email: string, password: string): Promise<SignupOutcome>;
|
|
34
39
|
/**
|
|
35
40
|
* Authenticate with email and password.
|
|
36
41
|
*/
|
|
@@ -54,6 +59,24 @@ export declare class T2VAuth {
|
|
|
54
59
|
* Check if a user is currently authenticated.
|
|
55
60
|
*/
|
|
56
61
|
isAuthenticated(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Return an access token valid *right now*, for a DIRECT request the SDK
|
|
64
|
+
* transport doesn't make for you — streaming straight to a third party, or a
|
|
65
|
+
* self-hosted backend on another origin. Proactively refreshes when the stored
|
|
66
|
+
* token is missing, expired, or within {@link TOKEN_EXPIRY_SKEW_SECONDS} of
|
|
67
|
+
* expiry; pass `forceRefresh` to refresh unconditionally (use that after a
|
|
68
|
+
* direct request still returns 401, e.g. clock skew or a server-side revoke).
|
|
69
|
+
*
|
|
70
|
+
* Refreshes are deduped with the SDK's own 401 handling, so a direct call and
|
|
71
|
+
* an in-flight SDK request never double-rotate the (rotating) refresh token.
|
|
72
|
+
* Returns null only when the session is genuinely dead (refresh token revoked
|
|
73
|
+
* or expired): auth is then cleared and listeners notified, so the app drops
|
|
74
|
+
* to logged-out. On a transient failure (network / 409 / 429) the existing
|
|
75
|
+
* token is returned so the caller can proceed or retry.
|
|
76
|
+
*/
|
|
77
|
+
getValidAccessToken(opts?: {
|
|
78
|
+
forceRefresh?: boolean;
|
|
79
|
+
}): Promise<string | null>;
|
|
57
80
|
/**
|
|
58
81
|
* Subscribe to auth state changes.
|
|
59
82
|
*/
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAe1C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAe1C,OAAO,KAAK,EAAgB,aAAa,EAAgC,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/F,KAAK,iBAAiB,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC;AAqCrD,qBAAa,OAAO;IAqBN,OAAO,CAAC,QAAQ,CAAC,MAAM;IApBnC,OAAO,CAAC,SAAS,CAAqC;IAGtD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAE5B;IAEF;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAC,SAAS,CAKxB;gBAE2B,MAAM,EAAE,SAAS;IAW9C;;;OAGG;IACH,OAAO,IAAI,IAAI;IAOf,oDAAoD;IAC9C,cAAc,CAAC,IAAI,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAerE,gEAAgE;IAChE,WAAW,IAAI,OAAO;IAItB;;;;;;;OAOG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAiCrE;;OAEG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB3D,OAAO,CAAC,UAAU,CAAC,CAAkB;IAErC,+DAA+D;IACzD,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAoCxC,iBAAiB;IAqD/B,mDAAmD;IACnD,OAAO,CAAC,KAAK;IAkBb;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAe7B;;OAEG;IACH,OAAO,IAAI,IAAI,GAAG,IAAI;IAUtB;;OAEG;IACH,eAAe,IAAI,OAAO;IAI1B;;;;;;;;;;;;;;OAcG;IACG,mBAAmB,CAAC,IAAI,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAiBpF;;OAEG;IACH,iBAAiB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,IAAI;IAO1D,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,eAAe;CAKxB"}
|
package/dist/auth.js
CHANGED
|
@@ -3,6 +3,35 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { AuthenticationError, T2VError } from './errors';
|
|
5
5
|
import { ACCESS_TOKEN_STORAGE_KEY, clearAuth, getAccessToken, getIsAnonymous, getUser, hasValidTokens, setAccessToken, setIsAnonymous, setUserApiKey, setRefreshToken, setUser, } from './storage';
|
|
6
|
+
// Refresh a token this many seconds before it actually expires, so a request
|
|
7
|
+
// fired right at the boundary doesn't race the expiry against clock skew.
|
|
8
|
+
const TOKEN_EXPIRY_SKEW_SECONDS = 30;
|
|
9
|
+
/**
|
|
10
|
+
* True when a JWT is expired or within the skew window of expiring. Returns
|
|
11
|
+
* false when the token can't be parsed or carries no numeric `exp` — we can't
|
|
12
|
+
* prove it's stale, so we let the reactive 401 path handle it rather than
|
|
13
|
+
* refresh on every call.
|
|
14
|
+
*/
|
|
15
|
+
function isExpiringSoon(token, skewSeconds = TOKEN_EXPIRY_SKEW_SECONDS) {
|
|
16
|
+
const exp = decodeJwtExp(token);
|
|
17
|
+
if (exp === null)
|
|
18
|
+
return false;
|
|
19
|
+
return exp - Date.now() / 1000 <= skewSeconds;
|
|
20
|
+
}
|
|
21
|
+
function decodeJwtExp(token) {
|
|
22
|
+
const payloadPart = token.split('.')[1];
|
|
23
|
+
if (!payloadPart || typeof atob !== 'function')
|
|
24
|
+
return null;
|
|
25
|
+
try {
|
|
26
|
+
const base64 = payloadPart.replace(/-/g, '+').replace(/_/g, '/');
|
|
27
|
+
const padded = base64 + '='.repeat((4 - (base64.length % 4)) % 4);
|
|
28
|
+
const payload = JSON.parse(atob(padded));
|
|
29
|
+
return typeof payload.exp === 'number' ? payload.exp : null;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
6
35
|
export class T2VAuth {
|
|
7
36
|
client;
|
|
8
37
|
listeners = new Set();
|
|
@@ -60,35 +89,38 @@ export class T2VAuth {
|
|
|
60
89
|
return getIsAnonymous();
|
|
61
90
|
}
|
|
62
91
|
/**
|
|
63
|
-
* Create a
|
|
92
|
+
* Create a permanent account.
|
|
93
|
+
*
|
|
94
|
+
* From an anonymous session this CONVERTS in place (same user id — history
|
|
95
|
+
* and purchases stay). The server emails a confirmation link; until it is
|
|
96
|
+
* clicked the session remains anonymous and `confirmationRequired` is true.
|
|
97
|
+
* A 409 means the email already has an account → we sign into it instead.
|
|
64
98
|
*/
|
|
65
99
|
async signup(email, password) {
|
|
66
100
|
if (getIsAnonymous()) {
|
|
67
101
|
try {
|
|
68
|
-
await this.client.request('/v1/auth/convert', { method: 'POST', body: JSON.stringify({ email, password }) }, true);
|
|
102
|
+
await this.client.request('/v1/auth/convert', { method: 'POST', body: JSON.stringify({ email, password, client: 'web-sdk' }) }, true);
|
|
103
|
+
return { user: null, confirmationRequired: true };
|
|
69
104
|
}
|
|
70
105
|
catch (err) {
|
|
71
|
-
|
|
72
|
-
// and log into it. Anything else is a real failure.
|
|
73
|
-
if (!(err instanceof T2VError && err.statusCode === 409)) {
|
|
106
|
+
if (!(err instanceof T2VError && err.statusCode === 409))
|
|
74
107
|
throw err;
|
|
75
|
-
|
|
108
|
+
const user = await this.login(email, password);
|
|
109
|
+
return { user, confirmationRequired: false };
|
|
76
110
|
}
|
|
77
|
-
// Convert links the credentials but revokes the anonymous session's
|
|
78
|
-
// refresh token server-side (Supabase rotates tokens on credential
|
|
79
|
-
// change), so the tokens we still hold are stale — the next refresh
|
|
80
|
-
// would 401. Re-authenticate to land a fresh session (same user_id on
|
|
81
|
-
// a successful convert → chat history preserved).
|
|
82
|
-
return await this.login(email, password);
|
|
83
111
|
}
|
|
84
112
|
const request = { email, password };
|
|
85
113
|
const response = await this.client.request('/v1/auth/signup', { method: 'POST', body: JSON.stringify(request) }, false);
|
|
86
|
-
this.storeTokens(response);
|
|
87
114
|
const user = response.user;
|
|
88
115
|
if (!user)
|
|
89
116
|
throw new AuthenticationError('Signup succeeded but no user returned');
|
|
117
|
+
if (!response.access_token) {
|
|
118
|
+
// Email confirmation enabled: no session until the link is clicked.
|
|
119
|
+
return { user, confirmationRequired: true };
|
|
120
|
+
}
|
|
121
|
+
this.storeTokens(response);
|
|
90
122
|
this.notifyListeners(user);
|
|
91
|
-
return user;
|
|
123
|
+
return { user, confirmationRequired: false };
|
|
92
124
|
}
|
|
93
125
|
/**
|
|
94
126
|
* Authenticate with email and password.
|
|
@@ -254,6 +286,38 @@ export class T2VAuth {
|
|
|
254
286
|
isAuthenticated() {
|
|
255
287
|
return hasValidTokens();
|
|
256
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* Return an access token valid *right now*, for a DIRECT request the SDK
|
|
291
|
+
* transport doesn't make for you — streaming straight to a third party, or a
|
|
292
|
+
* self-hosted backend on another origin. Proactively refreshes when the stored
|
|
293
|
+
* token is missing, expired, or within {@link TOKEN_EXPIRY_SKEW_SECONDS} of
|
|
294
|
+
* expiry; pass `forceRefresh` to refresh unconditionally (use that after a
|
|
295
|
+
* direct request still returns 401, e.g. clock skew or a server-side revoke).
|
|
296
|
+
*
|
|
297
|
+
* Refreshes are deduped with the SDK's own 401 handling, so a direct call and
|
|
298
|
+
* an in-flight SDK request never double-rotate the (rotating) refresh token.
|
|
299
|
+
* Returns null only when the session is genuinely dead (refresh token revoked
|
|
300
|
+
* or expired): auth is then cleared and listeners notified, so the app drops
|
|
301
|
+
* to logged-out. On a transient failure (network / 409 / 429) the existing
|
|
302
|
+
* token is returned so the caller can proceed or retry.
|
|
303
|
+
*/
|
|
304
|
+
async getValidAccessToken(opts) {
|
|
305
|
+
const current = getAccessToken();
|
|
306
|
+
const mustRefresh = opts?.forceRefresh === true || !current || isExpiringSoon(current);
|
|
307
|
+
if (!mustRefresh)
|
|
308
|
+
return current;
|
|
309
|
+
const result = await this.client.refreshTokens();
|
|
310
|
+
if (result === 'refreshed')
|
|
311
|
+
return getAccessToken();
|
|
312
|
+
if (result === 'invalid') {
|
|
313
|
+
// Genuinely dead session: clear + broadcast, same path as a 401 logout.
|
|
314
|
+
clearAuth();
|
|
315
|
+
this.notifyListeners(null);
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
// Transient (network / 409 / 429): keep the session, hand back what we have.
|
|
319
|
+
return current;
|
|
320
|
+
}
|
|
257
321
|
/**
|
|
258
322
|
* Subscribe to auth state changes.
|
|
259
323
|
*/
|
package/dist/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,M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AAC,QAAuB;QACzC,cAAc,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QACtC,eAAe,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QACxC,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;YAClB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QACD,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;YAC1B,aAAa,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QACvC,CAAC;QACD,cAAc,CAAC,QAAQ,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC;IACjD,CAAC;IAEO,eAAe,CAAC,IAAiB;QACvC,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACtC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;CACF"}
|
package/dist/client.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* HTTP/SSE API client with two-tier auth (partner key + user JWT).
|
|
3
3
|
*/
|
|
4
4
|
import type { ChatCompletionChunk, T2VConfig } from './types';
|
|
5
|
+
type RefreshResult = 'refreshed' | 'invalid' | 'transient';
|
|
5
6
|
export declare class T2VClient {
|
|
6
7
|
private readonly baseUrl;
|
|
7
8
|
private readonly partnerKey;
|
|
@@ -13,6 +14,23 @@ export declare class T2VClient {
|
|
|
13
14
|
* Create an AbortController that auto-aborts after the configured timeout.
|
|
14
15
|
*/
|
|
15
16
|
private makeTimeoutSignal;
|
|
17
|
+
/**
|
|
18
|
+
* Turn an aborted request into a NetworkError. A timeout abort carries a
|
|
19
|
+
* `TimeoutError` reason naming the real budget; any other abort (e.g. a bare
|
|
20
|
+
* `controller.abort()` on user-stop) falls back to a sensible timeout message
|
|
21
|
+
* rather than surfacing the platform's "The operation was aborted." string.
|
|
22
|
+
*/
|
|
23
|
+
private timeoutError;
|
|
24
|
+
/**
|
|
25
|
+
* Build a sanitized T2VError from a failed response.
|
|
26
|
+
*
|
|
27
|
+
* Only the structured, user-safe fields (`error.type` + `error.message`) and
|
|
28
|
+
* the HTTP status reach the thrown error's user-facing message. The server's
|
|
29
|
+
* raw `detail` (stack traces, DB errors, file paths) is kept on the separate
|
|
30
|
+
* `detail` property for debugging but never folded into `message`, so opaque
|
|
31
|
+
* HTML/text bodies or internal exception text cannot leak to end users.
|
|
32
|
+
*/
|
|
33
|
+
private errorFromResponse;
|
|
16
34
|
/**
|
|
17
35
|
* Execute a fetch with network-error wrapping, 401 refresh/retry, and error parsing.
|
|
18
36
|
*/
|
|
@@ -31,7 +49,7 @@ export declare class T2VClient {
|
|
|
31
49
|
* Make an authenticated multipart upload request (e.g. audio files).
|
|
32
50
|
* Does NOT set Content-Type — the browser sets it with the correct boundary.
|
|
33
51
|
*/
|
|
34
|
-
uploadRequest<T>(endpoint: string, formData: FormData, requiresAuth?: boolean): Promise<T>;
|
|
52
|
+
uploadRequest<T>(endpoint: string, formData: FormData, requiresAuth?: boolean, timeout?: number): Promise<T>;
|
|
35
53
|
/**
|
|
36
54
|
* Make an authenticated SSE streaming request.
|
|
37
55
|
*
|
|
@@ -41,7 +59,18 @@ export declare class T2VClient {
|
|
|
41
59
|
* outlive individual streams. The initial POST benefits from 401 refresh+retry.
|
|
42
60
|
*/
|
|
43
61
|
streamRequest(endpoint: string, body: object, externalSignal?: AbortSignal): AsyncGenerator<ChatCompletionChunk>;
|
|
62
|
+
/**
|
|
63
|
+
* Force a token refresh, deduped with in-flight 401-triggered refreshes.
|
|
64
|
+
*
|
|
65
|
+
* Exposed so that DIRECT (non-SDK-transport) callers — a frontend streaming
|
|
66
|
+
* straight to a third party, or a self-hosted backend on another origin that
|
|
67
|
+
* this client doesn't proxy — can share this client's single refresh authority
|
|
68
|
+
* instead of POSTing `/v1/auth/refresh` themselves and racing the rotation.
|
|
69
|
+
* Prefer {@link T2VAuth.getValidAccessToken} over calling this directly.
|
|
70
|
+
*/
|
|
71
|
+
refreshTokens(): Promise<RefreshResult>;
|
|
44
72
|
private tryRefreshToken;
|
|
45
73
|
private doRefreshToken;
|
|
46
74
|
}
|
|
75
|
+
export {};
|
|
47
76
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH,OAAO,KAAK,EACV,mBAAmB,EAEnB,SAAS,EACV,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH,OAAO,KAAK,EACV,mBAAmB,EAEnB,SAAS,EACV,MAAM,SAAS,CAAC;AAcjB,KAAK,aAAa,GAAG,WAAW,GAAG,SAAS,GAAG,WAAW,CAAC;AAE3D,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,cAAc,CAAuC;gBAEjD,MAAM,EAAE,SAAS;IAM7B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAYzB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IASpB;;;;;;;;OAQG;YACW,iBAAiB;IAe/B;;OAEG;YACW,aAAa;IA4D3B,OAAO,CAAC,YAAY;IAiBpB;;;OAGG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM;IAKvE;;OAEG;IACG,OAAO,CAAC,CAAC,EACb,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,WAAgB,EACzB,YAAY,UAAO,EACnB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,CAAC,CAAC;IAgBb;;;OAGG;IACG,aAAa,CAAC,CAAC,EACnB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,EAClB,YAAY,UAAO,EACnB,OAAO,GAAE,MAA+B,GACvC,OAAO,CAAC,CAAC,CAAC;IAiBb;;;;;;;OAOG;IACI,aAAa,CAClB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,cAAc,CAAC,EAAE,WAAW,GAC3B,cAAc,CAAC,mBAAmB,CAAC;IA+CtC;;;;;;;;OAQG;IACG,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC;YAI/B,eAAe;YAgBf,cAAc;CA0C7B"}
|
package/dist/client.js
CHANGED
|
@@ -6,6 +6,9 @@ import { clearAuth, getAccessToken, getRefreshToken, setAccessToken, setRefreshT
|
|
|
6
6
|
import { decodeSSEStream } from './streaming';
|
|
7
7
|
const DEFAULT_BASE_URL = 'https://engine.talk2view.com';
|
|
8
8
|
const DEFAULT_REQUEST_TIMEOUT = 30_000;
|
|
9
|
+
// Uploads (attachments, audio) move real bytes — a multi-MB file on a slow link
|
|
10
|
+
// or a busy backend easily exceeds the 30s API timeout. Give them a wider window.
|
|
11
|
+
const DEFAULT_UPLOAD_TIMEOUT = 120_000;
|
|
9
12
|
export class T2VClient {
|
|
10
13
|
baseUrl;
|
|
11
14
|
partnerKey;
|
|
@@ -21,10 +24,47 @@ export class T2VClient {
|
|
|
21
24
|
* Create an AbortController that auto-aborts after the configured timeout.
|
|
22
25
|
*/
|
|
23
26
|
makeTimeoutSignal(timeout) {
|
|
27
|
+
const ms = timeout ?? this.requestTimeout;
|
|
24
28
|
const controller = new AbortController();
|
|
25
|
-
|
|
29
|
+
// Carry the real budget in the abort reason so the surfaced error names the
|
|
30
|
+
// actual timeout (e.g. 120000ms for uploads), not a hardcoded default.
|
|
31
|
+
const timer = setTimeout(() => controller.abort(new DOMException(`Request timed out after ${ms}ms`, 'TimeoutError')), ms);
|
|
26
32
|
return { signal: controller.signal, clear: () => clearTimeout(timer) };
|
|
27
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Turn an aborted request into a NetworkError. A timeout abort carries a
|
|
36
|
+
* `TimeoutError` reason naming the real budget; any other abort (e.g. a bare
|
|
37
|
+
* `controller.abort()` on user-stop) falls back to a sensible timeout message
|
|
38
|
+
* rather than surfacing the platform's "The operation was aborted." string.
|
|
39
|
+
*/
|
|
40
|
+
timeoutError(signal) {
|
|
41
|
+
const reason = signal?.reason;
|
|
42
|
+
return new NetworkError(reason?.name === 'TimeoutError' && typeof reason.message === 'string'
|
|
43
|
+
? reason.message
|
|
44
|
+
: `Request timed out after ${this.requestTimeout}ms`);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Build a sanitized T2VError from a failed response.
|
|
48
|
+
*
|
|
49
|
+
* Only the structured, user-safe fields (`error.type` + `error.message`) and
|
|
50
|
+
* the HTTP status reach the thrown error's user-facing message. The server's
|
|
51
|
+
* raw `detail` (stack traces, DB errors, file paths) is kept on the separate
|
|
52
|
+
* `detail` property for debugging but never folded into `message`, so opaque
|
|
53
|
+
* HTML/text bodies or internal exception text cannot leak to end users.
|
|
54
|
+
*/
|
|
55
|
+
async errorFromResponse(response) {
|
|
56
|
+
const body = await response.json().catch(() => ({}));
|
|
57
|
+
// Server may wrap in { detail: { error: { ... } } } or { error: { ... } }.
|
|
58
|
+
const err = body?.detail?.error ?? body?.error ?? {};
|
|
59
|
+
const type = typeof err.type === 'string' ? err.type : undefined;
|
|
60
|
+
const safeMessage = typeof err.message === 'string' && err.message
|
|
61
|
+
? err.message
|
|
62
|
+
: `Request failed (HTTP ${response.status})`;
|
|
63
|
+
const code = typeof err.code === 'string' ? err.code : undefined;
|
|
64
|
+
// Keep the raw detail for debugging only — out of the user-facing message.
|
|
65
|
+
const detail = typeof err.detail === 'string' ? err.detail : undefined;
|
|
66
|
+
return new T2VError(safeMessage, type, response.status, code, detail);
|
|
67
|
+
}
|
|
28
68
|
/**
|
|
29
69
|
* Execute a fetch with network-error wrapping, 401 refresh/retry, and error parsing.
|
|
30
70
|
*/
|
|
@@ -35,8 +75,10 @@ export class T2VClient {
|
|
|
35
75
|
response = await fetch(`${this.baseUrl}${endpoint}`, fetchInit);
|
|
36
76
|
}
|
|
37
77
|
catch (err) {
|
|
38
|
-
|
|
39
|
-
|
|
78
|
+
// An abort (with a custom reason) rejects with the reason, not a plain
|
|
79
|
+
// AbortError — so key off signal.aborted rather than the caught value.
|
|
80
|
+
if (signal?.aborted) {
|
|
81
|
+
throw this.timeoutError(signal);
|
|
40
82
|
}
|
|
41
83
|
throw new NetworkError(`Request failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
42
84
|
}
|
|
@@ -50,15 +92,13 @@ export class T2VClient {
|
|
|
50
92
|
retryResponse = await fetch(`${this.baseUrl}${endpoint}`, retryInit);
|
|
51
93
|
}
|
|
52
94
|
catch (retryErr) {
|
|
53
|
-
if (
|
|
54
|
-
throw
|
|
95
|
+
if (signal?.aborted) {
|
|
96
|
+
throw this.timeoutError(signal);
|
|
55
97
|
}
|
|
56
98
|
throw new NetworkError(`Request failed: ${retryErr instanceof Error ? retryErr.message : 'Unknown error'}`);
|
|
57
99
|
}
|
|
58
100
|
if (!retryResponse.ok) {
|
|
59
|
-
|
|
60
|
-
const retryErr = retryBody?.detail?.error ?? retryBody?.error ?? {};
|
|
61
|
-
throw new T2VError(retryErr.message ?? 'Request failed', retryErr.type, retryResponse.status, retryErr.code);
|
|
101
|
+
throw await this.errorFromResponse(retryResponse);
|
|
62
102
|
}
|
|
63
103
|
return retryResponse;
|
|
64
104
|
}
|
|
@@ -72,10 +112,7 @@ export class T2VClient {
|
|
|
72
112
|
throw new NetworkError('Token refresh temporarily unavailable; please retry.');
|
|
73
113
|
}
|
|
74
114
|
if (!response.ok) {
|
|
75
|
-
|
|
76
|
-
// Server may wrap in { detail: { error: { ... } } } or { error: { ... } }
|
|
77
|
-
const err = body?.detail?.error ?? body?.error ?? {};
|
|
78
|
-
throw new T2VError(err.message ?? 'Request failed', err.type, response.status, err.code);
|
|
115
|
+
throw await this.errorFromResponse(response);
|
|
79
116
|
}
|
|
80
117
|
return response;
|
|
81
118
|
}
|
|
@@ -124,9 +161,9 @@ export class T2VClient {
|
|
|
124
161
|
* Make an authenticated multipart upload request (e.g. audio files).
|
|
125
162
|
* Does NOT set Content-Type — the browser sets it with the correct boundary.
|
|
126
163
|
*/
|
|
127
|
-
async uploadRequest(endpoint, formData, requiresAuth = true) {
|
|
164
|
+
async uploadRequest(endpoint, formData, requiresAuth = true, timeout = DEFAULT_UPLOAD_TIMEOUT) {
|
|
128
165
|
const headers = this.buildHeaders(requiresAuth);
|
|
129
|
-
const { signal, clear } = this.makeTimeoutSignal();
|
|
166
|
+
const { signal, clear } = this.makeTimeoutSignal(timeout);
|
|
130
167
|
try {
|
|
131
168
|
const response = await this.fetchWithAuth(endpoint, { method: 'POST', body: formData }, headers, requiresAuth, signal);
|
|
132
169
|
return response.json();
|
|
@@ -149,9 +186,11 @@ export class T2VClient {
|
|
|
149
186
|
// One controller drives the fetch. It aborts on connection timeout OR when
|
|
150
187
|
// the caller's external signal fires (user pressed "stop"). The timeout is
|
|
151
188
|
// cleared once the response arrives, leaving the external signal to abort the
|
|
152
|
-
// long-lived SSE body.
|
|
189
|
+
// long-lived SSE body. The timeout aborts with a TimeoutError reason so a
|
|
190
|
+
// connect-timeout surfaces "Request timed out after Nms", not the platform's
|
|
191
|
+
// opaque "The operation was aborted." default.
|
|
153
192
|
const controller = new AbortController();
|
|
154
|
-
const timer = setTimeout(() => controller.abort(), this.requestTimeout);
|
|
193
|
+
const timer = setTimeout(() => controller.abort(new DOMException(`Request timed out after ${this.requestTimeout}ms`, 'TimeoutError')), this.requestTimeout);
|
|
155
194
|
const onExternalAbort = () => controller.abort();
|
|
156
195
|
if (externalSignal) {
|
|
157
196
|
if (externalSignal.aborted)
|
|
@@ -176,6 +215,18 @@ export class T2VClient {
|
|
|
176
215
|
externalSignal?.removeEventListener('abort', onExternalAbort);
|
|
177
216
|
}
|
|
178
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Force a token refresh, deduped with in-flight 401-triggered refreshes.
|
|
220
|
+
*
|
|
221
|
+
* Exposed so that DIRECT (non-SDK-transport) callers — a frontend streaming
|
|
222
|
+
* straight to a third party, or a self-hosted backend on another origin that
|
|
223
|
+
* this client doesn't proxy — can share this client's single refresh authority
|
|
224
|
+
* instead of POSTing `/v1/auth/refresh` themselves and racing the rotation.
|
|
225
|
+
* Prefer {@link T2VAuth.getValidAccessToken} over calling this directly.
|
|
226
|
+
*/
|
|
227
|
+
async refreshTokens() {
|
|
228
|
+
return this.tryRefreshToken();
|
|
229
|
+
}
|
|
179
230
|
async tryRefreshToken() {
|
|
180
231
|
if (this.isRefreshing) {
|
|
181
232
|
return this.refreshPromise;
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,EACL,SAAS,EACT,cAAc,EACd,eAAe,EACf,cAAc,EACd,eAAe,GAChB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAO9C,MAAM,gBAAgB,GAAG,8BAA8B,CAAC;AACxD,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAUvC,MAAM,OAAO,SAAS;IACH,OAAO,CAAS;IAChB,UAAU,CAAS;IACnB,cAAc,CAAS;IAChC,YAAY,GAAG,KAAK,CAAC;IACrB,cAAc,GAAkC,IAAI,CAAC;IAE7D,YAAY,MAAiB;QAC3B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,gBAAgB,CAAC;QAClD,IAAI,CAAC,cAAc,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W,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared attachment constraints — the single source of truth for which file
|
|
3
|
+
* types the SDK will upload. Both the public `Talk2View.uploadAttachment()`
|
|
4
|
+
* guard and the bundled Composer derive from these, so partners with their own
|
|
5
|
+
* composer get the same client-side validation as the built-in UI.
|
|
6
|
+
*/
|
|
7
|
+
/** MIME whitelist (mirrors the server). Also drives the file input's `accept`. */
|
|
8
|
+
export declare const ATTACHMENT_ACCEPT = "image/png,image/jpeg,image/webp,image/gif,application/pdf";
|
|
9
|
+
/** The same whitelist as a Set, for O(1) membership checks. */
|
|
10
|
+
export declare const ALLOWED_ATTACHMENT_MIME: Set<string>;
|
|
11
|
+
/** Human-readable form of the whitelist, shown in hints and error messages. */
|
|
12
|
+
export declare const ATTACHMENT_TYPES_LABEL = "PNG, JPEG, WebP, GIF, or PDF";
|
|
13
|
+
/** True when `type` is an attachment MIME type the SDK (and server) accepts. */
|
|
14
|
+
export declare function isAllowedAttachmentType(type: string): boolean;
|
|
15
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,8DAA8D,CAAC;AAE7F,+DAA+D;AAC/D,eAAO,MAAM,uBAAuB,aAAwC,CAAC;AAE7E,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,iCAAiC,CAAC;AAErE,gFAAgF;AAChF,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared attachment constraints — the single source of truth for which file
|
|
3
|
+
* types the SDK will upload. Both the public `Talk2View.uploadAttachment()`
|
|
4
|
+
* guard and the bundled Composer derive from these, so partners with their own
|
|
5
|
+
* composer get the same client-side validation as the built-in UI.
|
|
6
|
+
*/
|
|
7
|
+
/** MIME whitelist (mirrors the server). Also drives the file input's `accept`. */
|
|
8
|
+
export const ATTACHMENT_ACCEPT = 'image/png,image/jpeg,image/webp,image/gif,application/pdf';
|
|
9
|
+
/** The same whitelist as a Set, for O(1) membership checks. */
|
|
10
|
+
export const ALLOWED_ATTACHMENT_MIME = new Set(ATTACHMENT_ACCEPT.split(','));
|
|
11
|
+
/** Human-readable form of the whitelist, shown in hints and error messages. */
|
|
12
|
+
export const ATTACHMENT_TYPES_LABEL = 'PNG, JPEG, WebP, GIF, or PDF';
|
|
13
|
+
/** True when `type` is an attachment MIME type the SDK (and server) accepts. */
|
|
14
|
+
export function isAllowedAttachmentType(type) {
|
|
15
|
+
return ALLOWED_ATTACHMENT_MIME.has(type);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,kFAAkF;AAClF,MAAM,CAAC,MAAM,iBAAiB,GAAG,2DAA2D,CAAC;AAE7F,+DAA+D;AAC/D,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAE7E,+EAA+E;AAC/E,MAAM,CAAC,MAAM,sBAAsB,GAAG,8BAA8B,CAAC;AAErE,gFAAgF;AAChF,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAClD,OAAO,uBAAuB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC3C,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Base error class for Talk2View SDK errors.
|
|
3
|
+
*
|
|
4
|
+
* `message` is always the user-safe summary (the server's structured
|
|
5
|
+
* `error.message` plus the HTTP status). The server's raw `detail` (stack
|
|
6
|
+
* traces, DB errors, file paths, library versions) is kept on the separate
|
|
7
|
+
* `detail` property for debugging and is NEVER folded into `message`, so it
|
|
8
|
+
* cannot leak to end users by default.
|
|
3
9
|
*/
|
|
4
10
|
export declare class T2VError extends Error {
|
|
5
11
|
readonly type: string;
|
|
6
12
|
readonly statusCode?: number | undefined;
|
|
7
13
|
readonly code?: string | undefined;
|
|
8
|
-
|
|
14
|
+
readonly detail?: string | undefined;
|
|
15
|
+
constructor(message: string, type?: string, statusCode?: number | undefined, code?: string | undefined, detail?: string | undefined);
|
|
9
16
|
}
|
|
10
17
|
export declare class AuthenticationError extends T2VError {
|
|
11
18
|
constructor(message: string);
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,QAAS,SAAQ,KAAK;aAGf,IAAI,EAAE,MAAM;aACZ,UAAU,CAAC,EAAE,MAAM;aACnB,IAAI,CAAC,EAAE,MAAM;aACb,MAAM,CAAC,EAAE,MAAM;gBAJ/B,OAAO,EAAE,MAAM,EACC,IAAI,GAAE,MAAoB,EAC1B,UAAU,CAAC,EAAE,MAAM,YAAA,EACnB,IAAI,CAAC,EAAE,MAAM,YAAA,EACb,MAAM,CAAC,EAAE,MAAM,YAAA;CAKlC;AAED,qBAAa,mBAAoB,SAAQ,QAAQ;gBACnC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,eAAgB,SAAQ,QAAQ;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,YAAa,SAAQ,QAAQ;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,YAAa,SAAQ,QAAQ;gBAC5B,OAAO,EAAE,MAAM;CAI5B"}
|
package/dist/errors.js
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Base error class for Talk2View SDK errors.
|
|
3
|
+
*
|
|
4
|
+
* `message` is always the user-safe summary (the server's structured
|
|
5
|
+
* `error.message` plus the HTTP status). The server's raw `detail` (stack
|
|
6
|
+
* traces, DB errors, file paths, library versions) is kept on the separate
|
|
7
|
+
* `detail` property for debugging and is NEVER folded into `message`, so it
|
|
8
|
+
* cannot leak to end users by default.
|
|
3
9
|
*/
|
|
4
10
|
export class T2VError extends Error {
|
|
5
11
|
type;
|
|
6
12
|
statusCode;
|
|
7
13
|
code;
|
|
8
|
-
|
|
14
|
+
detail;
|
|
15
|
+
constructor(message, type = 'sdk_error', statusCode, code, detail) {
|
|
9
16
|
super(message);
|
|
10
17
|
this.type = type;
|
|
11
18
|
this.statusCode = statusCode;
|
|
12
19
|
this.code = code;
|
|
20
|
+
this.detail = detail;
|
|
13
21
|
this.name = 'T2VError';
|
|
14
22
|
}
|
|
15
23
|
}
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGf;IACA;IACA;IACA;IALlB,YACE,OAAe,EACC,OAAe,WAAW,EAC1B,UAAmB,EACnB,IAAa,EACb,MAAe;QAE/B,KAAK,CAAC,OAAO,CAAC,CAAC;QALC,SAAI,GAAJ,IAAI,CAAsB;QAC1B,eAAU,GAAV,UAAU,CAAS;QACnB,SAAI,GAAJ,IAAI,CAAS;QACb,WAAM,GAAN,MAAM,CAAS;QAG/B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,QAAQ;IAC/C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,sBAAsB,EAAE,GAAG,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,QAAQ;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,mBAAmB,EAAE,GAAG,CAAC,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,QAAQ;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,QAAQ;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF"}
|