@talk2view/sdk 0.2.0-dev.1 → 0.2.1
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 +87 -1
- package/dist/client.d.ts +15 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +80 -97
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +2 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +3 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -1
- package/dist/react/ChatInput.d.ts +2 -1
- package/dist/react/ChatInput.d.ts.map +1 -1
- package/dist/react/ChatInput.js +13 -11
- package/dist/react/ChatInput.js.map +1 -1
- package/dist/react/ChatMessage.js +5 -5
- package/dist/react/ChatMessage.js.map +1 -1
- package/dist/react/ChatPanel.d.ts.map +1 -1
- package/dist/react/ChatPanel.js +40 -24
- package/dist/react/ChatPanel.js.map +1 -1
- package/dist/react/LoginModal.js +2 -2
- package/dist/react/LoginModal.js.map +1 -1
- package/dist/react/theme.d.ts +17 -0
- package/dist/react/theme.d.ts.map +1 -1
- package/dist/react/theme.js +18 -0
- package/dist/react/theme.js.map +1 -1
- package/dist/react/useT2VChat.d.ts.map +1 -1
- package/dist/react/useT2VChat.js +6 -5
- package/dist/react/useT2VChat.js.map +1 -1
- package/dist/react/useT2VTools.d.ts.map +1 -1
- package/dist/react/useT2VTools.js +8 -5
- package/dist/react/useT2VTools.js.map +1 -1
- package/dist/tools.d.ts +6 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +74 -2
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,6 +88,13 @@ Every request requires a partner API key (`X-T2V-Partner-Key` header). Keys are
|
|
|
88
88
|
|
|
89
89
|
The SDK attaches this header automatically.
|
|
90
90
|
|
|
91
|
+
**Partner keys are public identifiers**, not secrets. They identify your application but do not grant access to user data — every data-accessing request also requires a user JWT. It is safe to include partner keys in client-side bundles.
|
|
92
|
+
|
|
93
|
+
Best practices:
|
|
94
|
+
- Inject keys via environment variables at build time (e.g. `VITE_T2V_PARTNER_KEY`)
|
|
95
|
+
- Use separate `pk_test_` and `pk_live_` keys for development and production
|
|
96
|
+
- To rotate a key, generate a new key in the Talk2View dashboard, update your app, then deactivate the old key
|
|
97
|
+
|
|
91
98
|
### Two-Tier Authentication
|
|
92
99
|
|
|
93
100
|
Talk2View uses two layers of auth on every request:
|
|
@@ -196,6 +203,8 @@ const {
|
|
|
196
203
|
isLoading, // boolean — true while streaming
|
|
197
204
|
error, // string | null
|
|
198
205
|
threadId, // string | null
|
|
206
|
+
agentStatus, // { type: string; message: string } | null — real-time agent status
|
|
207
|
+
todos, // string — agent's current todo/plan text
|
|
199
208
|
sendMessage, // (content: string) => Promise<void>
|
|
200
209
|
clearMessages, // () => void
|
|
201
210
|
clearError, // () => void
|
|
@@ -320,6 +329,43 @@ for await (const event of t2v.chat('Zoom in please')) {
|
|
|
320
329
|
}
|
|
321
330
|
```
|
|
322
331
|
|
|
332
|
+
#### `t2v.clearSession()`
|
|
333
|
+
|
|
334
|
+
Reset the current session. Clears the thread ID so the next `chat()` call starts a fresh conversation.
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
t2v.clearSession();
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
#### `t2v.listModels()` / `t2v.listAudioModels()`
|
|
341
|
+
|
|
342
|
+
List available models:
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
const models = await t2v.listModels(); // Chat/completion models
|
|
346
|
+
const audioModels = await t2v.listAudioModels(); // Speech-to-text models
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
#### `t2v.transcribe()`
|
|
350
|
+
|
|
351
|
+
Transcribe an audio file using the server's speech-to-text service:
|
|
352
|
+
|
|
353
|
+
```typescript
|
|
354
|
+
const result = await t2v.transcribe(audioBlob, 'whisper-1', 'en');
|
|
355
|
+
console.log(result.text);
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
#### `t2v.completions()`
|
|
359
|
+
|
|
360
|
+
Send a raw completions request (non-streaming):
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
const response = await t2v.completions({
|
|
364
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
365
|
+
model: 'gpt-4.1-mini',
|
|
366
|
+
});
|
|
367
|
+
```
|
|
368
|
+
|
|
323
369
|
#### `t2v.createSession()` / `t2v.getSession()`
|
|
324
370
|
|
|
325
371
|
For advanced use cases where you need direct session control:
|
|
@@ -433,6 +479,19 @@ Stored keys:
|
|
|
433
479
|
|
|
434
480
|
On logout, all keys are cleared and a `talk2view_auth_cleared` event is dispatched on `window` for cross-component synchronization.
|
|
435
481
|
|
|
482
|
+
### Security Considerations
|
|
483
|
+
|
|
484
|
+
The SDK stores tokens in `localStorage` for persistence across page reloads. This is a deliberate trade-off — `localStorage` is accessible to any JavaScript running on the same origin, which means XSS vulnerabilities could expose tokens.
|
|
485
|
+
|
|
486
|
+
To mitigate this:
|
|
487
|
+
|
|
488
|
+
- **Use a Content Security Policy (CSP)** that restricts script sources to trusted origins
|
|
489
|
+
- **Keep token lifetimes short** — the SDK automatically refreshes tokens, so short-lived access tokens limit the window of exposure
|
|
490
|
+
- **Always serve your application over HTTPS**
|
|
491
|
+
- **Sanitize user-generated content** to prevent XSS injection
|
|
492
|
+
|
|
493
|
+
**CSRF protection:** The SDK sends a custom `X-T2V-Partner-Key` header on every request. Browsers block cross-origin requests with custom headers unless the server explicitly allows the origin via CORS. This makes CSRF attacks infeasible — a forged request from a malicious site would be blocked by the browser's preflight check.
|
|
494
|
+
|
|
436
495
|
---
|
|
437
496
|
|
|
438
497
|
## Error Handling
|
|
@@ -447,8 +506,10 @@ The SDK throws typed errors:
|
|
|
447
506
|
| `NetworkError` | Network failure, server unreachable |
|
|
448
507
|
| `T2VError` | Base class for all SDK errors |
|
|
449
508
|
|
|
509
|
+
All errors extend `T2VError`, which exposes `message`, `type`, `statusCode`, and `code`:
|
|
510
|
+
|
|
450
511
|
```typescript
|
|
451
|
-
import { AuthenticationError, NetworkError } from '@talk2view/sdk';
|
|
512
|
+
import { T2VError, AuthenticationError, NetworkError, SessionError } from '@talk2view/sdk';
|
|
452
513
|
|
|
453
514
|
try {
|
|
454
515
|
await t2v.auth.login(email, password);
|
|
@@ -457,14 +518,22 @@ try {
|
|
|
457
518
|
console.log('Bad credentials');
|
|
458
519
|
} else if (err instanceof NetworkError) {
|
|
459
520
|
console.log('Server unreachable');
|
|
521
|
+
} else if (err instanceof SessionError) {
|
|
522
|
+
console.log('Session issue:', err.message);
|
|
523
|
+
} else if (err instanceof T2VError) {
|
|
524
|
+
// Access the error code for programmatic handling
|
|
525
|
+
console.log(`Error [${err.code}]: ${err.message} (HTTP ${err.statusCode})`);
|
|
460
526
|
}
|
|
461
527
|
}
|
|
462
528
|
```
|
|
463
529
|
|
|
530
|
+
**Rate limiting:** The server may return HTTP 429 when rate limits are exceeded. This surfaces as a `T2VError` with `statusCode: 429`. Rate limiting is enforced server-side; implement app-level retry logic if needed.
|
|
531
|
+
|
|
464
532
|
In React, the hooks catch errors internally and expose them via the `error` state:
|
|
465
533
|
|
|
466
534
|
```tsx
|
|
467
535
|
const { error, clearError } = useT2VAuth();
|
|
536
|
+
const { error: chatError } = useT2VChat({ systemPrompt: '...' });
|
|
468
537
|
// error is a string message, not a thrown exception
|
|
469
538
|
```
|
|
470
539
|
|
|
@@ -479,6 +548,23 @@ const { error, clearError } = useT2VAuth();
|
|
|
479
548
|
| `partnerKey` | `string` | Yes | — | Your partner API key |
|
|
480
549
|
| `baseUrl` | `string` | No | `'http://localhost:8100'` | Talk2View API server URL |
|
|
481
550
|
| `model` | `string` | No | Server default | LLM model to use |
|
|
551
|
+
| `requestTimeout` | `number` | No | `30000` | HTTP request timeout in ms. Does not apply to SSE streams after connection. |
|
|
552
|
+
|
|
553
|
+
---
|
|
554
|
+
|
|
555
|
+
## System Prompts
|
|
556
|
+
|
|
557
|
+
System prompts set the AI's behavior and context for your application. Pass them to `ChatPanel` or `useT2VChat`:
|
|
558
|
+
|
|
559
|
+
```tsx
|
|
560
|
+
<ChatPanel systemPrompt="You are a medical imaging assistant. Use the provided tools to control the DICOM viewer." />
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
Best practices:
|
|
564
|
+
- **Keep prompts concise** — every token in the system prompt is sent with every request and adds to cost
|
|
565
|
+
- **Focus on tools and context** — describe what tools are available and when to use them, rather than general personality traits
|
|
566
|
+
- **Be specific about your domain** — mention the application type and expected user intents
|
|
567
|
+
- **Avoid conflicting instructions** — the system prompt should complement, not contradict, tool descriptions
|
|
482
568
|
|
|
483
569
|
---
|
|
484
570
|
|
package/dist/client.d.ts
CHANGED
|
@@ -5,9 +5,19 @@ import type { ChatCompletionChunk, T2VConfig } from './types';
|
|
|
5
5
|
export declare class T2VClient {
|
|
6
6
|
private readonly baseUrl;
|
|
7
7
|
private readonly partnerKey;
|
|
8
|
+
private readonly requestTimeout;
|
|
8
9
|
private isRefreshing;
|
|
9
10
|
private refreshPromise;
|
|
10
11
|
constructor(config: T2VConfig);
|
|
12
|
+
/**
|
|
13
|
+
* Create an AbortController that auto-aborts after the configured timeout.
|
|
14
|
+
*/
|
|
15
|
+
private makeTimeoutSignal;
|
|
16
|
+
/**
|
|
17
|
+
* Execute a fetch with network-error wrapping, 401 refresh/retry, and error parsing.
|
|
18
|
+
*/
|
|
19
|
+
private fetchWithAuth;
|
|
20
|
+
private buildHeaders;
|
|
11
21
|
/**
|
|
12
22
|
* Make an authenticated JSON request.
|
|
13
23
|
*/
|
|
@@ -19,6 +29,11 @@ export declare class T2VClient {
|
|
|
19
29
|
uploadRequest<T>(endpoint: string, formData: FormData, requiresAuth?: boolean): Promise<T>;
|
|
20
30
|
/**
|
|
21
31
|
* Make an authenticated SSE streaming request.
|
|
32
|
+
*
|
|
33
|
+
* The request timeout applies only to the initial POST (connection establishment).
|
|
34
|
+
* Once the SSE stream begins, no timeout is enforced — streams are long-lived by design.
|
|
35
|
+
* Mid-stream re-authentication is not supported; however, in practice access tokens
|
|
36
|
+
* outlive individual streams. The initial POST benefits from 401 refresh+retry.
|
|
22
37
|
*/
|
|
23
38
|
streamRequest(endpoint: string, body: object): AsyncGenerator<ChatCompletionChunk>;
|
|
24
39
|
private tryRefreshToken;
|
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;AAKjB,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,CAAiC;gBAE3C,MAAM,EAAE,SAAS;IAM7B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAMzB;;OAEG;YACW,aAAa;IAsD3B,OAAO,CAAC,YAAY;IAiBpB;;OAEG;IACG,OAAO,CAAC,CAAC,EACb,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,WAAgB,EACzB,YAAY,UAAO,GAClB,OAAO,CAAC,CAAC,CAAC;IAcb;;;OAGG;IACG,aAAa,CAAC,CAAC,EACnB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,EAClB,YAAY,UAAO,GAClB,OAAO,CAAC,CAAC,CAAC;IAiBb;;;;;;;OAOG;IACI,aAAa,CAClB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,cAAc,CAAC,mBAAmB,CAAC;YAmBxB,eAAe;YAgBf,cAAc;CAwB7B"}
|
package/dist/client.js
CHANGED
|
@@ -5,67 +5,75 @@ import { AuthenticationError, NetworkError, T2VError } from './errors';
|
|
|
5
5
|
import { clearAuth, getAccessToken, getRefreshToken, setAccessToken, setRefreshToken, } from './storage';
|
|
6
6
|
import { decodeSSEStream } from './streaming';
|
|
7
7
|
const DEFAULT_BASE_URL = 'https://engine.talk2view.com';
|
|
8
|
+
const DEFAULT_REQUEST_TIMEOUT = 30_000;
|
|
8
9
|
export class T2VClient {
|
|
9
10
|
baseUrl;
|
|
10
11
|
partnerKey;
|
|
12
|
+
requestTimeout;
|
|
11
13
|
isRefreshing = false;
|
|
12
14
|
refreshPromise = null;
|
|
13
15
|
constructor(config) {
|
|
14
16
|
this.partnerKey = config.partnerKey;
|
|
15
17
|
this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
18
|
+
this.requestTimeout = config.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT;
|
|
16
19
|
}
|
|
17
20
|
/**
|
|
18
|
-
*
|
|
21
|
+
* Create an AbortController that auto-aborts after the configured timeout.
|
|
19
22
|
*/
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
}
|
|
23
|
+
makeTimeoutSignal() {
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
const timer = setTimeout(() => controller.abort(), this.requestTimeout);
|
|
26
|
+
return { signal: controller.signal, clear: () => clearTimeout(timer) };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Execute a fetch with network-error wrapping, 401 refresh/retry, and error parsing.
|
|
30
|
+
*/
|
|
31
|
+
async fetchWithAuth(endpoint, init, headers, requiresAuth, signal) {
|
|
32
|
+
const fetchInit = signal ? { ...init, headers, signal } : { ...init, headers };
|
|
32
33
|
let response;
|
|
33
34
|
try {
|
|
34
|
-
response = await fetch(`${this.baseUrl}${endpoint}`,
|
|
35
|
+
response = await fetch(`${this.baseUrl}${endpoint}`, fetchInit);
|
|
35
36
|
}
|
|
36
37
|
catch (err) {
|
|
37
|
-
|
|
38
|
+
if (err instanceof DOMException && err.name === 'AbortError') {
|
|
39
|
+
throw new NetworkError(`Request timed out after ${this.requestTimeout}ms`);
|
|
40
|
+
}
|
|
41
|
+
throw new NetworkError(`Request failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
38
42
|
}
|
|
39
|
-
// Handle 401 — try to refresh token
|
|
40
43
|
if (response.status === 401 && requiresAuth) {
|
|
41
44
|
const refreshed = await this.tryRefreshToken();
|
|
42
45
|
if (refreshed) {
|
|
43
46
|
headers['Authorization'] = `Bearer ${getAccessToken()}`;
|
|
44
|
-
const
|
|
47
|
+
const retryInit = signal ? { ...init, headers, signal } : { ...init, headers };
|
|
48
|
+
let retryResponse;
|
|
49
|
+
try {
|
|
50
|
+
retryResponse = await fetch(`${this.baseUrl}${endpoint}`, retryInit);
|
|
51
|
+
}
|
|
52
|
+
catch (retryErr) {
|
|
53
|
+
if (retryErr instanceof DOMException && retryErr.name === 'AbortError') {
|
|
54
|
+
throw new NetworkError(`Request timed out after ${this.requestTimeout}ms`);
|
|
55
|
+
}
|
|
56
|
+
throw new NetworkError(`Request failed: ${retryErr instanceof Error ? retryErr.message : 'Unknown error'}`);
|
|
57
|
+
}
|
|
45
58
|
if (!retryResponse.ok) {
|
|
46
59
|
const error = await retryResponse.json().catch(() => ({ error: { message: 'Request failed' } }));
|
|
47
|
-
throw new T2VError(error?.error?.message ?? 'Request failed', error?.error?.type, retryResponse.status);
|
|
60
|
+
throw new T2VError(error?.error?.message ?? 'Request failed', error?.error?.type, retryResponse.status, error?.error?.code);
|
|
48
61
|
}
|
|
49
|
-
return retryResponse
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
clearAuth();
|
|
53
|
-
throw new AuthenticationError('Session expired. Please log in again.');
|
|
62
|
+
return retryResponse;
|
|
54
63
|
}
|
|
64
|
+
clearAuth();
|
|
65
|
+
throw new AuthenticationError('Session expired. Please log in again.');
|
|
55
66
|
}
|
|
56
67
|
if (!response.ok) {
|
|
57
68
|
const error = await response.json().catch(() => ({ error: { message: 'Request failed' } }));
|
|
58
|
-
throw new T2VError(error?.error?.message ?? 'Request failed', error?.error?.type, response.status);
|
|
69
|
+
throw new T2VError(error?.error?.message ?? 'Request failed', error?.error?.type, response.status, error?.error?.code);
|
|
59
70
|
}
|
|
60
|
-
return response
|
|
71
|
+
return response;
|
|
61
72
|
}
|
|
62
|
-
|
|
63
|
-
* Make an authenticated multipart upload request (e.g. audio files).
|
|
64
|
-
* Does NOT set Content-Type — the browser sets it with the correct boundary.
|
|
65
|
-
*/
|
|
66
|
-
async uploadRequest(endpoint, formData, requiresAuth = true) {
|
|
73
|
+
buildHeaders(requiresAuth, extra) {
|
|
67
74
|
const headers = {
|
|
68
75
|
'X-T2V-Partner-Key': this.partnerKey,
|
|
76
|
+
...extra,
|
|
69
77
|
};
|
|
70
78
|
if (requiresAuth) {
|
|
71
79
|
const token = getAccessToken();
|
|
@@ -73,83 +81,58 @@ export class T2VClient {
|
|
|
73
81
|
headers['Authorization'] = `Bearer ${token}`;
|
|
74
82
|
}
|
|
75
83
|
}
|
|
76
|
-
|
|
84
|
+
return headers;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Make an authenticated JSON request.
|
|
88
|
+
*/
|
|
89
|
+
async request(endpoint, options = {}, requiresAuth = true) {
|
|
90
|
+
const headers = this.buildHeaders(requiresAuth, {
|
|
91
|
+
'Content-Type': 'application/json',
|
|
92
|
+
...options.headers,
|
|
93
|
+
});
|
|
94
|
+
const { signal, clear } = this.makeTimeoutSignal();
|
|
77
95
|
try {
|
|
78
|
-
response = await
|
|
79
|
-
|
|
80
|
-
headers,
|
|
81
|
-
body: formData,
|
|
82
|
-
});
|
|
96
|
+
const response = await this.fetchWithAuth(endpoint, options, headers, requiresAuth, signal);
|
|
97
|
+
return response.json();
|
|
83
98
|
}
|
|
84
|
-
|
|
85
|
-
|
|
99
|
+
finally {
|
|
100
|
+
clear();
|
|
86
101
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const error = await retryResponse.json().catch(() => ({ error: { message: 'Upload failed' } }));
|
|
99
|
-
throw new T2VError(error?.error?.message ?? 'Upload failed', error?.error?.type, retryResponse.status);
|
|
100
|
-
}
|
|
101
|
-
return retryResponse.json();
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
clearAuth();
|
|
105
|
-
throw new AuthenticationError('Session expired. Please log in again.');
|
|
106
|
-
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Make an authenticated multipart upload request (e.g. audio files).
|
|
105
|
+
* Does NOT set Content-Type — the browser sets it with the correct boundary.
|
|
106
|
+
*/
|
|
107
|
+
async uploadRequest(endpoint, formData, requiresAuth = true) {
|
|
108
|
+
const headers = this.buildHeaders(requiresAuth);
|
|
109
|
+
const { signal, clear } = this.makeTimeoutSignal();
|
|
110
|
+
try {
|
|
111
|
+
const response = await this.fetchWithAuth(endpoint, { method: 'POST', body: formData }, headers, requiresAuth, signal);
|
|
112
|
+
return response.json();
|
|
107
113
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
throw new T2VError(error?.error?.message ?? 'Upload failed', error?.error?.type, response.status);
|
|
114
|
+
finally {
|
|
115
|
+
clear();
|
|
111
116
|
}
|
|
112
|
-
return response.json();
|
|
113
117
|
}
|
|
114
118
|
/**
|
|
115
119
|
* Make an authenticated SSE streaming request.
|
|
120
|
+
*
|
|
121
|
+
* The request timeout applies only to the initial POST (connection establishment).
|
|
122
|
+
* Once the SSE stream begins, no timeout is enforced — streams are long-lived by design.
|
|
123
|
+
* Mid-stream re-authentication is not supported; however, in practice access tokens
|
|
124
|
+
* outlive individual streams. The initial POST benefits from 401 refresh+retry.
|
|
116
125
|
*/
|
|
117
126
|
async *streamRequest(endpoint, body) {
|
|
118
|
-
const headers = {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
method: 'POST',
|
|
128
|
-
headers,
|
|
129
|
-
body: JSON.stringify(body),
|
|
130
|
-
});
|
|
131
|
-
if (!response.ok) {
|
|
132
|
-
if (response.status === 401) {
|
|
133
|
-
const refreshed = await this.tryRefreshToken();
|
|
134
|
-
if (refreshed) {
|
|
135
|
-
// Retry with new token
|
|
136
|
-
headers['Authorization'] = `Bearer ${getAccessToken()}`;
|
|
137
|
-
const retryResponse = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
138
|
-
method: 'POST',
|
|
139
|
-
headers,
|
|
140
|
-
body: JSON.stringify(body),
|
|
141
|
-
});
|
|
142
|
-
if (!retryResponse.ok) {
|
|
143
|
-
throw new T2VError('Stream request failed after token refresh');
|
|
144
|
-
}
|
|
145
|
-
yield* decodeSSEStream(retryResponse);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
clearAuth();
|
|
149
|
-
throw new AuthenticationError('Session expired. Please log in again.');
|
|
150
|
-
}
|
|
151
|
-
const error = await response.json().catch(() => ({ error: { message: 'Stream request failed' } }));
|
|
152
|
-
throw new T2VError(error?.error?.message ?? 'Stream request failed', error?.error?.type, response.status);
|
|
127
|
+
const headers = this.buildHeaders(true, { 'Content-Type': 'application/json' });
|
|
128
|
+
const serializedBody = JSON.stringify(body);
|
|
129
|
+
const { signal, clear } = this.makeTimeoutSignal();
|
|
130
|
+
let response;
|
|
131
|
+
try {
|
|
132
|
+
response = await this.fetchWithAuth(endpoint, { method: 'POST', body: serializedBody }, headers, true, signal);
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
clear();
|
|
153
136
|
}
|
|
154
137
|
yield* decodeSSEStream(response);
|
|
155
138
|
}
|
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;
|
|
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;AAEvC,MAAM,OAAO,SAAS;IACH,OAAO,CAAS;IAChB,UAAU,CAAS;IACnB,cAAc,CAAS;IAChC,YAAY,GAAG,KAAK,CAAC;IACrB,cAAc,GAA4B,IAAI,CAAC;IAEvD,YAAY,MAAiB;QAC3B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO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pD,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAClC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YACpC,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
export declare class T2VError extends Error {
|
|
5
5
|
readonly type: string;
|
|
6
6
|
readonly statusCode?: number | undefined;
|
|
7
|
-
|
|
7
|
+
readonly code?: string | undefined;
|
|
8
|
+
constructor(message: string, type?: string, statusCode?: number | undefined, code?: string | undefined);
|
|
8
9
|
}
|
|
9
10
|
export declare class AuthenticationError extends T2VError {
|
|
10
11
|
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;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;aAGf,IAAI,EAAE,MAAM;aACZ,UAAU,CAAC,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;aAGf,IAAI,EAAE,MAAM;aACZ,UAAU,CAAC,EAAE,MAAM;aACnB,IAAI,CAAC,EAAE,MAAM;gBAH7B,OAAO,EAAE,MAAM,EACC,IAAI,GAAE,MAAoB,EAC1B,UAAU,CAAC,EAAE,MAAM,YAAA,EACnB,IAAI,CAAC,EAAE,MAAM,YAAA;CAKhC;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
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
export class T2VError extends Error {
|
|
5
5
|
type;
|
|
6
6
|
statusCode;
|
|
7
|
-
|
|
7
|
+
code;
|
|
8
|
+
constructor(message, type = 'sdk_error', statusCode, code) {
|
|
8
9
|
super(message);
|
|
9
10
|
this.type = type;
|
|
10
11
|
this.statusCode = statusCode;
|
|
12
|
+
this.code = code;
|
|
11
13
|
this.name = 'T2VError';
|
|
12
14
|
}
|
|
13
15
|
}
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGf;IACA;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGf;IACA;IACA;IAJlB,YACE,OAAe,EACC,OAAe,WAAW,EAC1B,UAAmB,EACnB,IAAa;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,SAAI,GAAJ,IAAI,CAAsB;QAC1B,eAAU,GAAV,UAAU,CAAS;QACnB,SAAI,GAAJ,IAAI,CAAS;QAG7B,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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -28,12 +28,14 @@ import { T2VAuth } from './auth';
|
|
|
28
28
|
import { T2VSession } from './sessions';
|
|
29
29
|
import { T2VTools } from './tools';
|
|
30
30
|
import type { AudioModelsResponse, ChatEvent, ChatMessage, ModelsResponse, T2VConfig, TranscriptionResponse } from './types';
|
|
31
|
+
type SessionClearCallback = () => void;
|
|
31
32
|
export declare class Talk2View {
|
|
32
33
|
readonly auth: T2VAuth;
|
|
33
34
|
readonly tools: T2VTools;
|
|
34
35
|
private readonly client;
|
|
35
36
|
readonly config: T2VConfig;
|
|
36
37
|
private currentSession;
|
|
38
|
+
private sessionClearListeners;
|
|
37
39
|
constructor(config: T2VConfig);
|
|
38
40
|
/**
|
|
39
41
|
* Create a new chat session.
|
|
@@ -82,6 +84,16 @@ export declare class Talk2View {
|
|
|
82
84
|
* Also deletes the session on the server so conversation history is reset.
|
|
83
85
|
*/
|
|
84
86
|
clearSession(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Subscribe to session clear events.
|
|
89
|
+
*
|
|
90
|
+
* Listeners are called when {@link clearSession} runs. This allows hooks
|
|
91
|
+
* like `useT2VTools` to reset client-side state (e.g. tool registration)
|
|
92
|
+
* so that tools are re-registered on the next session.
|
|
93
|
+
*
|
|
94
|
+
* @returns An unsubscribe function.
|
|
95
|
+
*/
|
|
96
|
+
onSessionClear(callback: SessionClearCallback): () => void;
|
|
85
97
|
}
|
|
86
98
|
export { T2VAuth } from './auth';
|
|
87
99
|
export { T2VClient } from './client';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,WAAW,EAAS,cAAc,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEpI,qBAAa,SAAS;IACpB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,OAAO,CAAC,cAAc,CAA2B;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,WAAW,EAAS,cAAc,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEpI,KAAK,oBAAoB,GAAG,MAAM,IAAI,CAAC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QAAQ,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACtG,YAAY,EACV,SAAS,EACT,IAAI,EACJ,SAAS,EACT,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,mBAAmB,EACnB,qBAAqB,EACrB,KAAK,EACL,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,GAChB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ export class Talk2View {
|
|
|
34
34
|
client;
|
|
35
35
|
config;
|
|
36
36
|
currentSession = null;
|
|
37
|
+
sessionClearListeners = new Set();
|
|
37
38
|
constructor(config) {
|
|
38
39
|
if (config.voiceApiUrl) {
|
|
39
40
|
console.warn('[Talk2View] voiceApiUrl is deprecated and has no effect. ' +
|
|
@@ -113,6 +114,24 @@ export class Talk2View {
|
|
|
113
114
|
this.client.request(`/v1/sessions/${sessionId}`, { method: 'DELETE' }).catch(() => { });
|
|
114
115
|
}
|
|
115
116
|
this.currentSession = null;
|
|
117
|
+
for (const listener of this.sessionClearListeners) {
|
|
118
|
+
listener();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Subscribe to session clear events.
|
|
123
|
+
*
|
|
124
|
+
* Listeners are called when {@link clearSession} runs. This allows hooks
|
|
125
|
+
* like `useT2VTools` to reset client-side state (e.g. tool registration)
|
|
126
|
+
* so that tools are re-registered on the next session.
|
|
127
|
+
*
|
|
128
|
+
* @returns An unsubscribe function.
|
|
129
|
+
*/
|
|
130
|
+
onSessionClear(callback) {
|
|
131
|
+
this.sessionClearListeners.add(callback);
|
|
132
|
+
return () => {
|
|
133
|
+
this.sessionClearListeners.delete(callback);
|
|
134
|
+
};
|
|
116
135
|
}
|
|
117
136
|
}
|
|
118
137
|
// Re-export types and classes for consumers
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAKnC,MAAM,OAAO,SAAS;IACX,IAAI,CAAU;IACd,KAAK,CAAW;IACR,MAAM,CAAY;IAC1B,MAAM,CAAY;IACnB,cAAc,GAAsB,IAAI,CAAC;IACzC,qBAAqB,GAA8B,IAAI,GAAG,EAAE,CAAC;IAErE,YAAY,MAAiB;QAC3B,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;YACvB,OAAO,CAAC,IAAI,CACV,2DAA2D;gBAC3D,4CAA4C;gBAC5C,yCAAyC,CAC1C,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,CAAC,MA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AAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
export interface ChatInputProps {
|
|
7
7
|
onSend: (message: string) => void;
|
|
8
8
|
disabled?: boolean;
|
|
9
|
+
compact?: boolean;
|
|
9
10
|
placeholder?: string;
|
|
10
11
|
className?: string;
|
|
11
12
|
}
|
|
12
|
-
export declare function ChatInput({ onSend, disabled, placeholder, className, }: ChatInputProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function ChatInput({ onSend, disabled, compact, placeholder, className, }: ChatInputProps): import("react/jsx-runtime").JSX.Element;
|
|
13
14
|
//# sourceMappingURL=ChatInput.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatInput.d.ts","sourceRoot":"","sources":["../../src/react/ChatInput.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,SAAS,CAAC,EACxB,MAAM,EACN,QAAgB,EAChB,WAAiC,EACjC,SAAc,GACf,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"ChatInput.d.ts","sourceRoot":"","sources":["../../src/react/ChatInput.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,SAAS,CAAC,EACxB,MAAM,EACN,QAAgB,EAChB,OAAe,EACf,WAAiC,EACjC,SAAc,GACf,EAAE,cAAc,2CAkOhB"}
|