@bytexbyte/nxtlinq-ai-agent-web-development 0.1.2 → 0.1.5
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/createNxtlinqAgent.d.ts +1 -1
- package/dist/createNxtlinqAgent.js +1 -1
- package/dist/legacy/core/lib/useVoiceMode.d.ts.map +1 -1
- package/dist/legacy/core/lib/useVoiceMode.js +19 -0
- package/dist/webAgentDefaults.d.ts +1 -1
- package/dist/webAgentDefaults.js +1 -1
- package/package.json +2 -2
- package/src/createNxtlinqAgent.ts +1 -1
- package/src/legacy/core/lib/useVoiceMode.ts +18 -0
- package/src/webAgentDefaults.ts +1 -1
|
@@ -3,7 +3,7 @@ import { type CreateWebPlatformPortsOptions } from './ports/createWebPlatformPor
|
|
|
3
3
|
export type CreateNxtlinqAgentWebOptions = AgentConfig & CreateWebPlatformPortsOptions;
|
|
4
4
|
/**
|
|
5
5
|
* Create a platform-ready {@link NxtlinqAgent} for React Web custom UIs.
|
|
6
|
-
* Applies browser defaults (`voiceTransport:
|
|
6
|
+
* Applies browser defaults (`voiceTransport: ws-realtime`, `defaultModel`).
|
|
7
7
|
*/
|
|
8
8
|
export declare function createNxtlinqAgentWeb(options: CreateNxtlinqAgentWebOptions): NxtlinqAgent;
|
|
9
9
|
//# sourceMappingURL=createNxtlinqAgent.d.ts.map
|
|
@@ -3,7 +3,7 @@ import { createWebPlatformPorts, } from './ports/createWebPlatformPorts';
|
|
|
3
3
|
import { applyWebAgentDefaults } from './webAgentDefaults';
|
|
4
4
|
/**
|
|
5
5
|
* Create a platform-ready {@link NxtlinqAgent} for React Web custom UIs.
|
|
6
|
-
* Applies browser defaults (`voiceTransport:
|
|
6
|
+
* Applies browser defaults (`voiceTransport: ws-realtime`, `defaultModel`).
|
|
7
7
|
*/
|
|
8
8
|
export function createNxtlinqAgentWeb(options) {
|
|
9
9
|
const { storage, fetchImpl, getTimezone, webrtc, enableWebRTC, ...rawConfig } = options;
|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
|
@@ -361,6 +361,25 @@ export function useVoiceMode({ apiKey, apiSecret, pseudoId, externalId, aitId, w
|
|
|
361
361
|
};
|
|
362
362
|
}, [handleStatus, handleTranscriptTurn, handleTranscriptUi, handleDone]);
|
|
363
363
|
React.useEffect(() => () => { void stopVoiceSessionRef.current('unmount'); }, []);
|
|
364
|
+
// 追踪当前的 isVoiceMode 状态,用于 visibilitychange 事件
|
|
365
|
+
const isVoiceModeRef = React.useRef(isVoiceMode);
|
|
366
|
+
React.useEffect(() => {
|
|
367
|
+
isVoiceModeRef.current = isVoiceMode;
|
|
368
|
+
}, [isVoiceMode]);
|
|
369
|
+
// App 進入背景時立即退出語音 mode,防止後台語音連線異常斷開
|
|
370
|
+
React.useEffect(() => {
|
|
371
|
+
if (typeof document === 'undefined')
|
|
372
|
+
return;
|
|
373
|
+
const handleVisibilityChange = () => {
|
|
374
|
+
if (document.visibilityState !== 'hidden')
|
|
375
|
+
return;
|
|
376
|
+
if (!isVoiceModeRef.current)
|
|
377
|
+
return;
|
|
378
|
+
void exitVoiceMode();
|
|
379
|
+
};
|
|
380
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
381
|
+
return () => document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
382
|
+
}, [exitVoiceMode]);
|
|
364
383
|
return {
|
|
365
384
|
isVoiceMode,
|
|
366
385
|
voiceStatus,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AgentConfig } from '@bytexbyte/nxtlinq-ai-agent-core-development';
|
|
2
2
|
/** Browser SDK defaults — integrators do not pass these props. */
|
|
3
3
|
export declare const WEB_AGENT_DEFAULTS: {
|
|
4
|
-
readonly voiceTransport: "
|
|
4
|
+
readonly voiceTransport: "ws-realtime";
|
|
5
5
|
readonly voiceMode: "realtime";
|
|
6
6
|
readonly defaultModel: "open-ai-stream";
|
|
7
7
|
};
|
package/dist/webAgentDefaults.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytexbyte/nxtlinq-ai-agent-web-development",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "React Web headless SDK for nxtlinq AI Agent — hooks and browser ports",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"universal-cookie": "^8.0.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@bytexbyte/nxtlinq-ai-agent-core-development": "
|
|
48
|
+
"@bytexbyte/nxtlinq-ai-agent-core-development": "workspace:^",
|
|
49
49
|
"@types/react": "^18.2.64",
|
|
50
50
|
"@types/react-dom": "^18.2.25",
|
|
51
51
|
"react": "^18.2.0",
|
|
@@ -13,7 +13,7 @@ export type CreateNxtlinqAgentWebOptions = AgentConfig & CreateWebPlatformPortsO
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Create a platform-ready {@link NxtlinqAgent} for React Web custom UIs.
|
|
16
|
-
* Applies browser defaults (`voiceTransport:
|
|
16
|
+
* Applies browser defaults (`voiceTransport: ws-realtime`, `defaultModel`).
|
|
17
17
|
*/
|
|
18
18
|
export function createNxtlinqAgentWeb(options: CreateNxtlinqAgentWebOptions): NxtlinqAgent {
|
|
19
19
|
const {
|
|
@@ -401,6 +401,24 @@ export function useVoiceMode({
|
|
|
401
401
|
|
|
402
402
|
React.useEffect(() => () => { void stopVoiceSessionRef.current('unmount'); }, []);
|
|
403
403
|
|
|
404
|
+
// 追踪当前的 isVoiceMode 状态,用于 visibilitychange 事件
|
|
405
|
+
const isVoiceModeRef = React.useRef(isVoiceMode);
|
|
406
|
+
React.useEffect(() => {
|
|
407
|
+
isVoiceModeRef.current = isVoiceMode;
|
|
408
|
+
}, [isVoiceMode]);
|
|
409
|
+
|
|
410
|
+
// App 進入背景時立即退出語音 mode,防止後台語音連線異常斷開
|
|
411
|
+
React.useEffect(() => {
|
|
412
|
+
if (typeof document === 'undefined') return;
|
|
413
|
+
const handleVisibilityChange = () => {
|
|
414
|
+
if (document.visibilityState !== 'hidden') return;
|
|
415
|
+
if (!isVoiceModeRef.current) return;
|
|
416
|
+
void exitVoiceMode();
|
|
417
|
+
};
|
|
418
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
419
|
+
return () => document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
420
|
+
}, [exitVoiceMode]);
|
|
421
|
+
|
|
404
422
|
return {
|
|
405
423
|
isVoiceMode,
|
|
406
424
|
voiceStatus,
|
package/src/webAgentDefaults.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { AgentConfig } from '@bytexbyte/nxtlinq-ai-agent-core-development';
|
|
|
2
2
|
|
|
3
3
|
/** Browser SDK defaults — integrators do not pass these props. */
|
|
4
4
|
export const WEB_AGENT_DEFAULTS = {
|
|
5
|
-
voiceTransport: '
|
|
5
|
+
voiceTransport: 'ws-realtime',
|
|
6
6
|
voiceMode: 'realtime',
|
|
7
7
|
defaultModel: 'open-ai-stream',
|
|
8
8
|
} as const satisfies Partial<AgentConfig>;
|