@celljs/ta-web 4.35.0 → 4.36.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/esm/browser/assistant/assistant-thread.js +2 -2
- package/esm/browser/assistant/mic-capture.d.ts +34 -0
- package/esm/browser/assistant/mic-capture.js +87 -0
- package/esm/browser/assistant/realtime-voice.d.ts +2 -2
- package/esm/browser/assistant/realtime-voice.js +6 -15
- package/esm/browser/components/board.d.ts +2 -2
- package/esm/browser/components/board.js +2 -2
- package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
- package/esm/browser/components/composer-box-hooks.d.ts +12 -0
- package/esm/browser/components/composer-box-hooks.js +12 -0
- package/esm/browser/components/composer-box-protocol.d.ts +12 -1
- package/esm/browser/components/composer-box.js +14 -11
- package/esm/browser/components/composer.js +69 -3
- package/esm/browser/components/extension-settings.d.ts +7 -0
- package/esm/browser/components/extension-settings.js +32 -0
- package/esm/browser/components/host-view.d.ts +1 -1
- package/esm/browser/components/message-list.js +3 -3
- package/esm/browser/components/message-steps.js +3 -3
- package/esm/browser/components/phone-shell.d.ts +2 -2
- package/esm/browser/components/request-error.d.ts +9 -0
- package/esm/browser/components/request-error.js +21 -0
- package/esm/browser/components/settings-more.js +7 -24
- package/esm/browser/components/storage-settings.d.ts +17 -0
- package/esm/browser/components/storage-settings.js +145 -0
- package/esm/browser/extension/web-api-contributions.d.ts +6 -7
- package/esm/browser/extension/web-api-spec.js +2 -0
- package/esm/browser/extension/web-api-targets.d.ts +11 -0
- package/esm/browser/extension/web-api-targets.js +2 -0
- package/esm/browser/extension/web-extension-api.d.ts +5 -1
- package/esm/browser/extension/web-extension-context.d.ts +3 -2
- package/esm/browser/extension/web-extension-context.js +11 -15
- package/esm/browser/extension/web-extension-run.d.ts +2 -0
- package/esm/browser/extension/web-extension-run.js +12 -0
- package/esm/browser/extension/web-extensions-running.d.ts +2 -0
- package/esm/browser/extension/web-extensions-running.js +5 -0
- package/esm/browser/extension/web-extensions.js +1 -0
- package/esm/browser/game/game-control.d.ts +6 -0
- package/esm/browser/game/game-control.js +28 -0
- package/esm/browser/game/game-host.d.ts +9 -2
- package/esm/browser/game/game-host.js +5 -1
- package/esm/browser/game/game-protocol.d.ts +8 -0
- package/esm/browser/game/game-runner.d.ts +7 -1
- package/esm/browser/game/game-runner.js +24 -2
- package/esm/browser/game/game-target.d.ts +22 -0
- package/esm/browser/game/game-target.js +84 -0
- package/esm/browser/game/game-util.d.ts +2 -0
- package/esm/browser/game/game-util.js +2 -0
- package/esm/browser/game/game-view.d.ts +5 -2
- package/esm/browser/game/game-view.js +4 -4
- package/esm/browser/game/game3d-protocol.d.ts +3 -1
- package/esm/browser/game/game3d-runner.d.ts +6 -1
- package/esm/browser/game/game3d-runner.js +26 -2
- package/esm/browser/i18n/en/chat.d.ts +4 -0
- package/esm/browser/i18n/en/chat.js +4 -0
- package/esm/browser/i18n/en/settings.d.ts +15 -0
- package/esm/browser/i18n/en/settings.js +15 -0
- package/esm/browser/i18n/ja/chat.js +4 -0
- package/esm/browser/i18n/ja/settings.js +15 -0
- package/esm/browser/i18n/locales.d.ts +20 -1
- package/esm/browser/i18n/messages.d.ts +19 -0
- package/esm/browser/i18n/zh/chat.js +4 -0
- package/esm/browser/i18n/zh/settings.js +15 -0
- package/esm/browser/i18n/zh-tw/chat.js +4 -0
- package/esm/browser/i18n/zh-tw/settings.js +15 -0
- package/esm/browser/index.d.ts +2 -0
- package/esm/browser/index.js +2 -0
- package/esm/browser/sandbox/remote/remote-copy.d.ts +1 -0
- package/esm/browser/sandbox/remote/remote-copy.js +16 -0
- package/esm/browser/sandbox/sandbox-runtime-code.js +1 -1
- package/esm/browser/settings/agent-settings.js +5 -1
- package/esm/browser/style/pages.d.ts +1 -1
- package/esm/browser/style/pages.js +2 -0
- package/esm/browser/style/surfaces.d.ts +1 -1
- package/esm/browser/style/surfaces.js +2 -3
- package/esm/browser/targets/targets-protocol.d.ts +54 -0
- package/esm/browser/targets/targets-protocol.js +34 -0
- package/esm/browser/targets/targets.d.ts +13 -0
- package/esm/browser/targets/targets.js +64 -0
- package/esm/browser/util/composer.d.ts +4 -2
- package/esm/browser/util/composer.js +7 -1
- package/esm/browser/util/message.d.ts +6 -0
- package/esm/browser/util/message.js +21 -0
- package/esm/browser/util/process.d.ts +1 -0
- package/esm/browser/util/process.js +6 -1
- package/esm/browser/util/progress.d.ts +2 -1
- package/esm/browser/util/progress.js +2 -11
- package/lib/browser/assistant/assistant-thread.js +2 -2
- package/lib/browser/assistant/mic-capture.d.ts +35 -0
- package/lib/browser/assistant/mic-capture.js +91 -0
- package/lib/browser/assistant/realtime-voice.d.ts +2 -2
- package/lib/browser/assistant/realtime-voice.js +6 -15
- package/lib/browser/components/board.d.ts +2 -2
- package/lib/browser/components/board.js +2 -2
- package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
- package/lib/browser/components/composer-box-hooks.d.ts +12 -0
- package/lib/browser/components/composer-box-hooks.js +13 -0
- package/lib/browser/components/composer-box-protocol.d.ts +12 -1
- package/lib/browser/components/composer-box.js +13 -10
- package/lib/browser/components/composer.js +69 -3
- package/lib/browser/components/extension-settings.d.ts +8 -0
- package/lib/browser/components/extension-settings.js +69 -0
- package/lib/browser/components/host-view.d.ts +1 -1
- package/lib/browser/components/message-list.js +3 -3
- package/lib/browser/components/message-steps.js +3 -3
- package/lib/browser/components/phone-shell.d.ts +2 -2
- package/lib/browser/components/request-error.d.ts +10 -0
- package/lib/browser/components/request-error.js +57 -0
- package/lib/browser/components/settings-more.js +6 -23
- package/lib/browser/components/storage-settings.d.ts +18 -0
- package/lib/browser/components/storage-settings.js +182 -0
- package/lib/browser/extension/web-api-contributions.d.ts +6 -7
- package/lib/browser/extension/web-api-spec.js +2 -0
- package/lib/browser/extension/web-api-targets.d.ts +12 -0
- package/lib/browser/extension/web-api-targets.js +3 -0
- package/lib/browser/extension/web-extension-api.d.ts +5 -1
- package/lib/browser/extension/web-extension-context.d.ts +3 -2
- package/lib/browser/extension/web-extension-context.js +11 -15
- package/lib/browser/extension/web-extension-run.d.ts +2 -0
- package/lib/browser/extension/web-extension-run.js +12 -0
- package/lib/browser/extension/web-extensions-running.d.ts +2 -0
- package/lib/browser/extension/web-extensions-running.js +5 -0
- package/lib/browser/extension/web-extensions.js +1 -0
- package/lib/browser/game/game-control.d.ts +6 -0
- package/lib/browser/game/game-control.js +28 -0
- package/lib/browser/game/game-host.d.ts +9 -2
- package/lib/browser/game/game-host.js +5 -1
- package/lib/browser/game/game-protocol.d.ts +8 -0
- package/lib/browser/game/game-runner.d.ts +7 -1
- package/lib/browser/game/game-runner.js +24 -2
- package/lib/browser/game/game-target.d.ts +23 -0
- package/lib/browser/game/game-target.js +87 -0
- package/lib/browser/game/game-util.d.ts +2 -0
- package/lib/browser/game/game-util.js +2 -0
- package/lib/browser/game/game-view.d.ts +5 -2
- package/lib/browser/game/game-view.js +4 -4
- package/lib/browser/game/game3d-protocol.d.ts +3 -1
- package/lib/browser/game/game3d-runner.d.ts +6 -1
- package/lib/browser/game/game3d-runner.js +26 -2
- package/lib/browser/i18n/en/chat.d.ts +4 -0
- package/lib/browser/i18n/en/chat.js +4 -0
- package/lib/browser/i18n/en/settings.d.ts +15 -0
- package/lib/browser/i18n/en/settings.js +15 -0
- package/lib/browser/i18n/ja/chat.js +4 -0
- package/lib/browser/i18n/ja/settings.js +15 -0
- package/lib/browser/i18n/locales.d.ts +20 -1
- package/lib/browser/i18n/messages.d.ts +19 -0
- package/lib/browser/i18n/zh/chat.js +4 -0
- package/lib/browser/i18n/zh/settings.js +15 -0
- package/lib/browser/i18n/zh-tw/chat.js +4 -0
- package/lib/browser/i18n/zh-tw/settings.js +15 -0
- package/lib/browser/index.d.ts +2 -0
- package/lib/browser/index.js +2 -0
- package/lib/browser/sandbox/remote/remote-copy.d.ts +1 -0
- package/lib/browser/sandbox/remote/remote-copy.js +16 -0
- package/lib/browser/sandbox/sandbox-runtime-code.js +1 -1
- package/lib/browser/settings/agent-settings.js +5 -1
- package/lib/browser/style/pages.d.ts +1 -1
- package/lib/browser/style/pages.js +2 -0
- package/lib/browser/style/surfaces.d.ts +1 -1
- package/lib/browser/style/surfaces.js +2 -3
- package/lib/browser/targets/targets-protocol.d.ts +55 -0
- package/lib/browser/targets/targets-protocol.js +37 -0
- package/lib/browser/targets/targets.d.ts +14 -0
- package/lib/browser/targets/targets.js +67 -0
- package/lib/browser/util/composer.d.ts +4 -2
- package/lib/browser/util/composer.js +7 -1
- package/lib/browser/util/message.d.ts +6 -0
- package/lib/browser/util/message.js +21 -0
- package/lib/browser/util/process.d.ts +1 -0
- package/lib/browser/util/process.js +6 -1
- package/lib/browser/util/progress.d.ts +2 -1
- package/lib/browser/util/progress.js +2 -11
- package/package.json +7 -7
|
@@ -23,6 +23,27 @@ export var MessageUtil;
|
|
|
23
23
|
return stopReason === 'error' && errorMessage && ABORTED.test(errorMessage.trim()) ? 'aborted' : stopReason;
|
|
24
24
|
}
|
|
25
25
|
MessageUtil.stopReason = stopReason;
|
|
26
|
+
/**
|
|
27
|
+
* The last message of the user while nothing came of it yet: after it only thinking, no words and no tool
|
|
28
|
+
* called. Stopped then, it goes back into the box to change and send again (a rewind to it, as pi's
|
|
29
|
+
* `/tree`); one with images does not, since the box would lose them.
|
|
30
|
+
*/
|
|
31
|
+
function unanswered(messages) {
|
|
32
|
+
let index = messages.length - 1;
|
|
33
|
+
for (; index >= 0; index--) {
|
|
34
|
+
const { role } = messages[index];
|
|
35
|
+
if (role === 'user') {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
const done = role !== 'assistant' || blocks(messages[index]).some(block => { var _a; return block.type === 'toolCall' || (block.type === 'text' && !!((_a = block.text) === null || _a === void 0 ? void 0 : _a.trim())); });
|
|
39
|
+
if (done) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const message = messages[index];
|
|
44
|
+
return message && !blocks(message).some(block => block.type === 'image') && text(blocks(message)).trim() ? message : undefined;
|
|
45
|
+
}
|
|
46
|
+
MessageUtil.unanswered = unanswered;
|
|
26
47
|
function blocks(message) {
|
|
27
48
|
const content = message.content;
|
|
28
49
|
if (typeof content === 'string') {
|
|
@@ -103,6 +103,11 @@ export var ProcessUtil;
|
|
|
103
103
|
function resumed(message) {
|
|
104
104
|
return message.customType === TA_RESUME_MESSAGE;
|
|
105
105
|
}
|
|
106
|
+
/** The note that the network was back and it went on with the run the network stopped (TaNetworkResume). */
|
|
107
|
+
function resumedOnline(message) {
|
|
108
|
+
var _a;
|
|
109
|
+
return ((_a = message.details) === null || _a === void 0 ? void 0 : _a.reason) === 'network';
|
|
110
|
+
}
|
|
106
111
|
/** `message`, of the user, was written before `previous`, of the agent, came: while the agent worked. */
|
|
107
112
|
function writtenBefore(message, previous) {
|
|
108
113
|
const { role, timestamp } = message;
|
|
@@ -123,7 +128,7 @@ export var ProcessUtil;
|
|
|
123
128
|
steps.push({ kind: 'said', key: `${start + offset}.u`, message });
|
|
124
129
|
}
|
|
125
130
|
if (resumed(message)) {
|
|
126
|
-
steps.push({ kind: 'resumed', key: `${start + offset}.r
|
|
131
|
+
steps.push({ kind: 'resumed', key: `${start + offset}.r`, ...(resumedOnline(message) ? { online: true } : {}) });
|
|
127
132
|
}
|
|
128
133
|
if (role !== 'assistant') {
|
|
129
134
|
return;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SessionState } from '@celljs/ta-client';
|
|
2
|
+
import { type TaRequestErrorReason } from '@celljs/ta-protocol';
|
|
2
3
|
import type { WebToolRendererResolver } from '../extension/web-extension-api.js';
|
|
3
4
|
import type { Translate } from '../i18n/use-t.js';
|
|
4
5
|
import { type ToolSummary } from './tool.js';
|
|
@@ -39,7 +40,7 @@ export type Phase = {
|
|
|
39
40
|
error?: string;
|
|
40
41
|
};
|
|
41
42
|
/** Why pi retries, read from the error of the provider: what the loading line says before its countdown. */
|
|
42
|
-
export type RetryReason =
|
|
43
|
+
export type RetryReason = TaRequestErrorReason;
|
|
43
44
|
/** Tokens of the run of now: sent to the model (each request counts its whole context) and received from it. */
|
|
44
45
|
export interface RunTokens {
|
|
45
46
|
input: number;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TaRequestErrorUtil } from '@celljs/ta-protocol';
|
|
1
2
|
import { MessageUtil } from './message.js';
|
|
2
3
|
import { ToolUtil } from './tool.js';
|
|
3
4
|
/** pi's estimate, for what a model has not counted yet: four characters a token. */
|
|
@@ -104,17 +105,7 @@ export var ProgressUtil;
|
|
|
104
105
|
ProgressUtil.brief = brief;
|
|
105
106
|
/** Why a request failed, as the provider said it: a rate limit, a model too busy, the network, or another error. */
|
|
106
107
|
function retryReason(errorMessage) {
|
|
107
|
-
|
|
108
|
-
if (/\b429\b|rate.?limit|too many requests|quota|usage limit/i.test(message)) {
|
|
109
|
-
return 'rateLimit';
|
|
110
|
-
}
|
|
111
|
-
if (/overload|\b529\b|\b503\b|capacity|unavailable/i.test(message)) {
|
|
112
|
-
return 'overloaded';
|
|
113
|
-
}
|
|
114
|
-
if (/fetch failed|network|socket|ECONN|ETIMEDOUT|ENOTFOUND|EAI_AGAIN|timed? ?out|terminated/i.test(message)) {
|
|
115
|
-
return 'network';
|
|
116
|
-
}
|
|
117
|
-
return 'error';
|
|
108
|
+
return TaRequestErrorUtil.reason(errorMessage);
|
|
118
109
|
}
|
|
119
110
|
ProgressUtil.retryReason = retryReason;
|
|
120
111
|
/** The seconds left of a wait of `delayMs` that began at `since`, rounded up: 0 once it is over. */
|
|
@@ -37,7 +37,6 @@ exports.AssistantThread = void 0;
|
|
|
37
37
|
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
38
38
|
const lucide_react_1 = require("lucide-react");
|
|
39
39
|
const React = __importStar(require("react"));
|
|
40
|
-
const callout_1 = require("../components/callout");
|
|
41
40
|
const context_line_1 = require("../components/context-line");
|
|
42
41
|
const conversation_scroll_util_1 = require("../components/conversation-scroll-util");
|
|
43
42
|
const icon_1 = require("../components/icon");
|
|
@@ -47,6 +46,7 @@ const message_list_1 = require("../components/message-list");
|
|
|
47
46
|
const message_menu_1 = require("../components/message-menu");
|
|
48
47
|
const message_steps_1 = require("../components/message-steps");
|
|
49
48
|
const message_user_1 = require("../components/message-user");
|
|
49
|
+
const request_error_1 = require("../components/request-error");
|
|
50
50
|
const run_status_1 = require("../components/run-status");
|
|
51
51
|
const extension_view_1 = require("../extension/extension-view");
|
|
52
52
|
const web_tasks_1 = require("../extension/web-tasks");
|
|
@@ -93,7 +93,7 @@ function DoubleRowView({ item, tools, mood, status, latest, started, onTask, t }
|
|
|
93
93
|
React.createElement(message_steps_1.Process, { steps: item.steps, active: item.active, results: results, tools: tools, leading: React.createElement(message_list_1.TurnAvatar, { mood: mood }), status: status }),
|
|
94
94
|
React.createElement(task_views_1.TaskCards, { tasks: started }),
|
|
95
95
|
item.reply.map((text, index) => (React.createElement(markdown_1.Markdown, { key: index, text: text, streaming: item.active && index === item.reply.length - 1 }))),
|
|
96
|
-
!item.active && stopReason === 'error' && errorMessage && React.createElement(
|
|
96
|
+
!item.active && stopReason === 'error' && errorMessage && React.createElement(request_error_1.RequestError, { error: errorMessage })));
|
|
97
97
|
}
|
|
98
98
|
const { role } = item.message;
|
|
99
99
|
if (role === 'custom') {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** No sound from the microphone this long while it should hear: it no longer does (the audio was interrupted). */
|
|
2
|
+
export declare const STALL_MS = 4000;
|
|
3
|
+
/** Muted by the system (a phone call) this long: it no longer hears, though no sound stopped coming. */
|
|
4
|
+
export declare const MUTED_MS = 1000;
|
|
5
|
+
/** How often it looks. */
|
|
6
|
+
export declare const CHECK_MS = 1000;
|
|
7
|
+
/**
|
|
8
|
+
* The microphone heard through an audio context: its samples go to `heard`, and `lost` is told once as it stops
|
|
9
|
+
* hearing without a word from the recognizer, which would otherwise wait for sound that never comes: the track ended
|
|
10
|
+
* (unplugged, taken), the system muted it (a phone call) or no sound came for STALL_MS (the context was interrupted or
|
|
11
|
+
* suspended). Asleep meanwhile (a page in the background whose timers stopped), it does not count the time.
|
|
12
|
+
*/
|
|
13
|
+
export declare class MicCapture {
|
|
14
|
+
protected readonly stream: MediaStream;
|
|
15
|
+
protected readonly lost: (error: string) => void;
|
|
16
|
+
protected readonly now: () => number;
|
|
17
|
+
protected processor?: ScriptProcessorNode;
|
|
18
|
+
protected soundAt: number;
|
|
19
|
+
protected checkedAt: number;
|
|
20
|
+
protected mutedAt?: number;
|
|
21
|
+
protected timer?: ReturnType<typeof setInterval>;
|
|
22
|
+
protected done: boolean;
|
|
23
|
+
protected readonly ended: () => void;
|
|
24
|
+
protected readonly muted: () => void;
|
|
25
|
+
protected readonly unmuted: () => void;
|
|
26
|
+
constructor(stream: MediaStream, lost: (error: string) => void, now?: () => number);
|
|
27
|
+
/** Hears it through `context`, from now on watched. */
|
|
28
|
+
hear(context: AudioContext, heard: (samples: Float32Array) => void): void;
|
|
29
|
+
/** Looks whether it still hears. */
|
|
30
|
+
check(): void;
|
|
31
|
+
/** Lets go of the microphone. */
|
|
32
|
+
stop(): void;
|
|
33
|
+
protected lose(error: string): void;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=mic-capture.d.ts.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MicCapture = exports.CHECK_MS = exports.MUTED_MS = exports.STALL_MS = void 0;
|
|
4
|
+
/** No sound from the microphone this long while it should hear: it no longer does (the audio was interrupted). */
|
|
5
|
+
exports.STALL_MS = 4000;
|
|
6
|
+
/** Muted by the system (a phone call) this long: it no longer hears, though no sound stopped coming. */
|
|
7
|
+
exports.MUTED_MS = 1000;
|
|
8
|
+
/** How often it looks. */
|
|
9
|
+
exports.CHECK_MS = 1000;
|
|
10
|
+
/**
|
|
11
|
+
* The microphone heard through an audio context: its samples go to `heard`, and `lost` is told once as it stops
|
|
12
|
+
* hearing without a word from the recognizer, which would otherwise wait for sound that never comes: the track ended
|
|
13
|
+
* (unplugged, taken), the system muted it (a phone call) or no sound came for STALL_MS (the context was interrupted or
|
|
14
|
+
* suspended). Asleep meanwhile (a page in the background whose timers stopped), it does not count the time.
|
|
15
|
+
*/
|
|
16
|
+
class MicCapture {
|
|
17
|
+
constructor(stream, lost, now = Date.now) {
|
|
18
|
+
this.stream = stream;
|
|
19
|
+
this.lost = lost;
|
|
20
|
+
this.now = now;
|
|
21
|
+
this.soundAt = 0;
|
|
22
|
+
this.checkedAt = 0;
|
|
23
|
+
this.done = false;
|
|
24
|
+
this.ended = () => this.lose('audio-capture');
|
|
25
|
+
this.muted = () => {
|
|
26
|
+
this.mutedAt = this.now();
|
|
27
|
+
};
|
|
28
|
+
this.unmuted = () => {
|
|
29
|
+
this.mutedAt = undefined;
|
|
30
|
+
};
|
|
31
|
+
for (const track of stream.getAudioTracks()) {
|
|
32
|
+
track.addEventListener('ended', this.ended);
|
|
33
|
+
track.addEventListener('mute', this.muted);
|
|
34
|
+
track.addEventListener('unmute', this.unmuted);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Hears it through `context`, from now on watched. */
|
|
38
|
+
hear(context, heard) {
|
|
39
|
+
const source = context.createMediaStreamSource(this.stream);
|
|
40
|
+
this.processor = context.createScriptProcessor(4096, 1, 1);
|
|
41
|
+
this.processor.onaudioprocess = event => {
|
|
42
|
+
this.soundAt = this.now();
|
|
43
|
+
heard(event.inputBuffer.getChannelData(0));
|
|
44
|
+
};
|
|
45
|
+
source.connect(this.processor);
|
|
46
|
+
// Connected so that it runs; it writes nothing, its output is silence.
|
|
47
|
+
this.processor.connect(context.destination);
|
|
48
|
+
this.soundAt = this.checkedAt = this.now();
|
|
49
|
+
this.timer = setInterval(() => this.check(), exports.CHECK_MS);
|
|
50
|
+
}
|
|
51
|
+
/** Looks whether it still hears. */
|
|
52
|
+
check() {
|
|
53
|
+
const now = this.now();
|
|
54
|
+
if (now - this.checkedAt > exports.CHECK_MS * 3) {
|
|
55
|
+
// It slept: what it missed meanwhile is not the microphone's doing.
|
|
56
|
+
this.soundAt = now;
|
|
57
|
+
this.mutedAt = this.mutedAt === undefined ? undefined : now;
|
|
58
|
+
}
|
|
59
|
+
this.checkedAt = now;
|
|
60
|
+
if (this.mutedAt !== undefined && now - this.mutedAt >= exports.MUTED_MS) {
|
|
61
|
+
this.lose('interrupted');
|
|
62
|
+
}
|
|
63
|
+
else if (now - this.soundAt >= exports.STALL_MS) {
|
|
64
|
+
this.lose('audio-capture');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Lets go of the microphone. */
|
|
68
|
+
stop() {
|
|
69
|
+
this.done = true;
|
|
70
|
+
clearInterval(this.timer);
|
|
71
|
+
if (this.processor) {
|
|
72
|
+
this.processor.onaudioprocess = null;
|
|
73
|
+
this.processor.disconnect();
|
|
74
|
+
}
|
|
75
|
+
for (const track of this.stream.getTracks()) {
|
|
76
|
+
track.removeEventListener('ended', this.ended);
|
|
77
|
+
track.removeEventListener('mute', this.muted);
|
|
78
|
+
track.removeEventListener('unmute', this.unmuted);
|
|
79
|
+
track.stop();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
lose(error) {
|
|
83
|
+
if (!this.done) {
|
|
84
|
+
this.done = true;
|
|
85
|
+
clearInterval(this.timer);
|
|
86
|
+
this.lost(error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.MicCapture = MicCapture;
|
|
91
|
+
//# sourceMappingURL=mic-capture.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TaBargeIn, type TaVoiceBrainRef, type TaVoiceEvent, type TaVoiceSession } from '@celljs/ta-protocol';
|
|
2
2
|
import { Voice } from '../util/voice';
|
|
3
|
+
import { MicCapture } from './mic-capture';
|
|
3
4
|
import { MicSense } from './mic-sense';
|
|
4
5
|
import { MicFilter } from './noise-gate';
|
|
5
6
|
import { type Doubt, type Hearing, type Reading, type RealtimeVoiceHost, Talking } from './realtime-voice-protocol';
|
|
@@ -20,8 +21,7 @@ export declare class RealtimeVoice implements CallVoice {
|
|
|
20
21
|
/** How loud what plays is, after the lowering: what the microphone may hear back of it. */
|
|
21
22
|
protected played?: AnalyserNode;
|
|
22
23
|
protected doubt?: Doubt;
|
|
23
|
-
protected
|
|
24
|
-
protected processor?: ScriptProcessorNode;
|
|
24
|
+
protected capture?: MicCapture;
|
|
25
25
|
protected offEvents?: () => void;
|
|
26
26
|
protected hearing?: Hearing;
|
|
27
27
|
protected reading?: Reading;
|
|
@@ -4,6 +4,7 @@ exports.RealtimeVoice = void 0;
|
|
|
4
4
|
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
5
5
|
const turn_end_1 = require("../util/turn-end");
|
|
6
6
|
const voice_1 = require("../util/voice");
|
|
7
|
+
const mic_capture_1 = require("./mic-capture");
|
|
7
8
|
const mic_sense_1 = require("./mic-sense");
|
|
8
9
|
const noise_gate_1 = require("./noise-gate");
|
|
9
10
|
const pcm_util_1 = require("./pcm-util");
|
|
@@ -60,18 +61,15 @@ class RealtimeVoice {
|
|
|
60
61
|
await this.context.resume().catch(() => undefined);
|
|
61
62
|
return this;
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
64
65
|
audio: { echoCancellation: true, noiseSuppression: true, autoGainControl: true, channelCount: 1 },
|
|
65
66
|
});
|
|
67
|
+
// Taken from it (a phone call, unplugged, the audio interrupted), it is gone: it would wait for sound in vain.
|
|
68
|
+
this.capture = new mic_capture_1.MicCapture(stream, error => this.lose(error));
|
|
66
69
|
this.context = new Context();
|
|
67
70
|
this.output(this.context);
|
|
68
71
|
await this.context.resume().catch(() => undefined);
|
|
69
|
-
|
|
70
|
-
this.processor = this.context.createScriptProcessor(4096, 1, 1);
|
|
71
|
-
this.processor.onaudioprocess = event => this.captured(event.inputBuffer.getChannelData(0));
|
|
72
|
-
source.connect(this.processor);
|
|
73
|
-
// Connected so that it runs; it writes nothing, its output is silence.
|
|
74
|
-
this.processor.connect(this.context.destination);
|
|
72
|
+
this.capture.hear(this.context, samples => this.captured(samples));
|
|
75
73
|
return this;
|
|
76
74
|
}
|
|
77
75
|
catch (error) {
|
|
@@ -169,7 +167,6 @@ class RealtimeVoice {
|
|
|
169
167
|
}
|
|
170
168
|
stop() {
|
|
171
169
|
var _a, _b, _c, _d;
|
|
172
|
-
var _e;
|
|
173
170
|
if (this.stopped)
|
|
174
171
|
return;
|
|
175
172
|
const gone = this.closed;
|
|
@@ -180,13 +177,7 @@ class RealtimeVoice {
|
|
|
180
177
|
this.clearDoubt();
|
|
181
178
|
(_a = this.offEvents) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
182
179
|
(_b = this.offState) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
183
|
-
|
|
184
|
-
this.processor.onaudioprocess = null;
|
|
185
|
-
this.processor.disconnect();
|
|
186
|
-
}
|
|
187
|
-
for (const track of (_e = (_c = this.stream) === null || _c === void 0 ? void 0 : _c.getTracks()) !== null && _e !== void 0 ? _e : []) {
|
|
188
|
-
track.stop();
|
|
189
|
-
}
|
|
180
|
+
(_c = this.capture) === null || _c === void 0 ? void 0 : _c.stop();
|
|
190
181
|
void ((_d = this.context) === null || _d === void 0 ? void 0 : _d.close().catch(() => undefined));
|
|
191
182
|
if (this.session && !gone) {
|
|
192
183
|
void this.host.voice.closeVoice(this.session.voiceId).catch(() => undefined);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* The board (ta-launcher.md): the cards of web extensions (`location: 'board'`), as the user arranged them;
|
|
4
|
-
* Edit takes cards off, puts them back and orders them. A phone brings it
|
|
5
|
-
* first tab, the rail elsewhere. `leading` is before the title (back, on a phone).
|
|
4
|
+
* Edit takes cards off, puts them back and orders them. A phone brings it in from the left with a swipe to the
|
|
5
|
+
* right over its first tab, the rail elsewhere. `leading` is before the title (back, on a phone).
|
|
6
6
|
*/
|
|
7
7
|
export declare function BoardSurface({ leading }: {
|
|
8
8
|
leading?: React.ReactNode;
|
|
@@ -100,8 +100,8 @@ function BoardEditor({ shown, hidden, arrangement, onChange, }) {
|
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
102
|
* The board (ta-launcher.md): the cards of web extensions (`location: 'board'`), as the user arranged them;
|
|
103
|
-
* Edit takes cards off, puts them back and orders them. A phone brings it
|
|
104
|
-
* first tab, the rail elsewhere. `leading` is before the title (back, on a phone).
|
|
103
|
+
* Edit takes cards off, puts them back and orders them. A phone brings it in from the left with a swipe to the
|
|
104
|
+
* right over its first tab, the rail elsewhere. `leading` is before the title (back, on a phone).
|
|
105
105
|
*/
|
|
106
106
|
function BoardSurface({ leading }) {
|
|
107
107
|
const t = (0, use_t_1.useT)();
|