@openclaw/google-meet 2026.5.2 → 2026.5.3-beta.2
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/calendar-6EQiwLUb.js +126 -0
- package/dist/chrome-create-B0wV2zaj.js +963 -0
- package/dist/cli-CSyT9_N6.js +1377 -0
- package/dist/create-0ye_2zVk.js +106 -0
- package/dist/index.js +3509 -0
- package/dist/oauth-BJwzuzT-.js +141 -0
- package/package.json +13 -6
- package/google-meet.live.test.ts +0 -85
- package/index.create.test.ts +0 -595
- package/index.test.ts +0 -3616
- package/index.ts +0 -1170
- package/node-host.test.ts +0 -222
- package/src/agent-consult.ts +0 -70
- package/src/calendar.ts +0 -243
- package/src/cli.test.ts +0 -1013
- package/src/cli.ts +0 -2136
- package/src/config.ts +0 -509
- package/src/create.ts +0 -153
- package/src/drive.ts +0 -72
- package/src/google-api-errors.ts +0 -20
- package/src/meet.ts +0 -1024
- package/src/node-host.ts +0 -498
- package/src/oauth.test.ts +0 -71
- package/src/oauth.ts +0 -229
- package/src/realtime-node.ts +0 -271
- package/src/realtime.ts +0 -423
- package/src/runtime.ts +0 -804
- package/src/setup.ts +0 -276
- package/src/test-support/plugin-harness.ts +0 -225
- package/src/transports/chrome-browser-proxy.ts +0 -198
- package/src/transports/chrome-create.ts +0 -367
- package/src/transports/chrome.ts +0 -925
- package/src/transports/twilio.ts +0 -46
- package/src/transports/types.ts +0 -113
- package/src/voice-call-gateway.test.ts +0 -79
- package/src/voice-call-gateway.ts +0 -213
- package/tsconfig.json +0 -16
package/src/oauth.ts
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import { generateHexPkceVerifierChallenge } from "openclaw/plugin-sdk/provider-auth";
|
|
2
|
-
import {
|
|
3
|
-
generateOAuthState,
|
|
4
|
-
parseOAuthCallbackInput,
|
|
5
|
-
waitForLocalOAuthCallback,
|
|
6
|
-
} from "openclaw/plugin-sdk/provider-auth-runtime";
|
|
7
|
-
import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
8
|
-
|
|
9
|
-
const GOOGLE_MEET_REDIRECT_URI = "http://localhost:8085/oauth2callback";
|
|
10
|
-
const GOOGLE_MEET_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
11
|
-
const GOOGLE_MEET_TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
12
|
-
const GOOGLE_MEET_TOKEN_HOST = "oauth2.googleapis.com";
|
|
13
|
-
const GOOGLE_MEET_SCOPES = [
|
|
14
|
-
"https://www.googleapis.com/auth/meetings.space.created",
|
|
15
|
-
"https://www.googleapis.com/auth/meetings.space.readonly",
|
|
16
|
-
"https://www.googleapis.com/auth/meetings.space.settings",
|
|
17
|
-
"https://www.googleapis.com/auth/meetings.conference.media.readonly",
|
|
18
|
-
"https://www.googleapis.com/auth/calendar.events.readonly",
|
|
19
|
-
"https://www.googleapis.com/auth/drive.meet.readonly",
|
|
20
|
-
] as const;
|
|
21
|
-
|
|
22
|
-
export type GoogleMeetOAuthTokens = {
|
|
23
|
-
accessToken: string;
|
|
24
|
-
expiresAt: number;
|
|
25
|
-
refreshToken?: string;
|
|
26
|
-
scope?: string;
|
|
27
|
-
tokenType?: string;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export function buildGoogleMeetAuthUrl(params: {
|
|
31
|
-
clientId: string;
|
|
32
|
-
challenge: string;
|
|
33
|
-
state: string;
|
|
34
|
-
redirectUri?: string;
|
|
35
|
-
scopes?: readonly string[];
|
|
36
|
-
}): string {
|
|
37
|
-
const search = new URLSearchParams({
|
|
38
|
-
client_id: params.clientId,
|
|
39
|
-
response_type: "code",
|
|
40
|
-
redirect_uri: params.redirectUri ?? GOOGLE_MEET_REDIRECT_URI,
|
|
41
|
-
scope: (params.scopes ?? GOOGLE_MEET_SCOPES).join(" "),
|
|
42
|
-
code_challenge: params.challenge,
|
|
43
|
-
code_challenge_method: "S256",
|
|
44
|
-
access_type: "offline",
|
|
45
|
-
prompt: "consent",
|
|
46
|
-
state: params.state,
|
|
47
|
-
});
|
|
48
|
-
return `${GOOGLE_MEET_AUTH_URL}?${search.toString()}`;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function executeGoogleTokenRequest(body: URLSearchParams): Promise<GoogleMeetOAuthTokens> {
|
|
52
|
-
const { response, release } = await fetchWithSsrFGuard({
|
|
53
|
-
url: GOOGLE_MEET_TOKEN_URL,
|
|
54
|
-
init: {
|
|
55
|
-
method: "POST",
|
|
56
|
-
headers: {
|
|
57
|
-
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
|
58
|
-
Accept: "application/json",
|
|
59
|
-
},
|
|
60
|
-
body,
|
|
61
|
-
},
|
|
62
|
-
policy: { allowedHostnames: [GOOGLE_MEET_TOKEN_HOST] },
|
|
63
|
-
auditContext: "google-meet.oauth.token",
|
|
64
|
-
});
|
|
65
|
-
try {
|
|
66
|
-
if (!response.ok) {
|
|
67
|
-
const detail = await response.text();
|
|
68
|
-
throw new Error(`Google OAuth token request failed (${response.status}): ${detail}`);
|
|
69
|
-
}
|
|
70
|
-
const payload = (await response.json()) as {
|
|
71
|
-
access_token?: string;
|
|
72
|
-
expires_in?: number;
|
|
73
|
-
refresh_token?: string;
|
|
74
|
-
scope?: string;
|
|
75
|
-
token_type?: string;
|
|
76
|
-
};
|
|
77
|
-
const accessToken = payload.access_token?.trim();
|
|
78
|
-
if (!accessToken) {
|
|
79
|
-
throw new Error("Google OAuth token response was missing access_token");
|
|
80
|
-
}
|
|
81
|
-
const expiresInSeconds =
|
|
82
|
-
typeof payload.expires_in === "number" && Number.isFinite(payload.expires_in)
|
|
83
|
-
? payload.expires_in
|
|
84
|
-
: 3600;
|
|
85
|
-
return {
|
|
86
|
-
accessToken,
|
|
87
|
-
expiresAt: Date.now() + expiresInSeconds * 1000,
|
|
88
|
-
refreshToken: payload.refresh_token?.trim() || undefined,
|
|
89
|
-
scope: payload.scope?.trim() || undefined,
|
|
90
|
-
tokenType: payload.token_type?.trim() || undefined,
|
|
91
|
-
};
|
|
92
|
-
} finally {
|
|
93
|
-
await release();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function tokenRequestBody(values: Record<string, string | undefined>): URLSearchParams {
|
|
98
|
-
const body = new URLSearchParams();
|
|
99
|
-
for (const [key, value] of Object.entries(values)) {
|
|
100
|
-
if (value?.trim()) {
|
|
101
|
-
body.set(key, value);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return body;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export async function exchangeGoogleMeetAuthCode(params: {
|
|
108
|
-
clientId: string;
|
|
109
|
-
clientSecret?: string;
|
|
110
|
-
code: string;
|
|
111
|
-
verifier: string;
|
|
112
|
-
redirectUri?: string;
|
|
113
|
-
}): Promise<GoogleMeetOAuthTokens> {
|
|
114
|
-
return await executeGoogleTokenRequest(
|
|
115
|
-
tokenRequestBody({
|
|
116
|
-
client_id: params.clientId,
|
|
117
|
-
client_secret: params.clientSecret,
|
|
118
|
-
code: params.code,
|
|
119
|
-
grant_type: "authorization_code",
|
|
120
|
-
redirect_uri: params.redirectUri ?? GOOGLE_MEET_REDIRECT_URI,
|
|
121
|
-
code_verifier: params.verifier,
|
|
122
|
-
}),
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export async function refreshGoogleMeetAccessToken(params: {
|
|
127
|
-
clientId: string;
|
|
128
|
-
clientSecret?: string;
|
|
129
|
-
refreshToken: string;
|
|
130
|
-
}): Promise<GoogleMeetOAuthTokens> {
|
|
131
|
-
return await executeGoogleTokenRequest(
|
|
132
|
-
tokenRequestBody({
|
|
133
|
-
client_id: params.clientId,
|
|
134
|
-
client_secret: params.clientSecret,
|
|
135
|
-
grant_type: "refresh_token",
|
|
136
|
-
refresh_token: params.refreshToken,
|
|
137
|
-
}),
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function shouldUseCachedGoogleMeetAccessToken(params: {
|
|
142
|
-
accessToken?: string;
|
|
143
|
-
expiresAt?: number;
|
|
144
|
-
now?: number;
|
|
145
|
-
safetyWindowMs?: number;
|
|
146
|
-
}): boolean {
|
|
147
|
-
const now = params.now ?? Date.now();
|
|
148
|
-
const safetyWindowMs = params.safetyWindowMs ?? 60_000;
|
|
149
|
-
return Boolean(
|
|
150
|
-
params.accessToken?.trim() &&
|
|
151
|
-
typeof params.expiresAt === "number" &&
|
|
152
|
-
Number.isFinite(params.expiresAt) &&
|
|
153
|
-
params.expiresAt > now + safetyWindowMs,
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export async function resolveGoogleMeetAccessToken(params: {
|
|
158
|
-
clientId?: string;
|
|
159
|
-
clientSecret?: string;
|
|
160
|
-
refreshToken?: string;
|
|
161
|
-
accessToken?: string;
|
|
162
|
-
expiresAt?: number;
|
|
163
|
-
}): Promise<{ accessToken: string; expiresAt?: number; refreshed: boolean }> {
|
|
164
|
-
if (shouldUseCachedGoogleMeetAccessToken(params)) {
|
|
165
|
-
return {
|
|
166
|
-
accessToken: params.accessToken!.trim(),
|
|
167
|
-
expiresAt: params.expiresAt,
|
|
168
|
-
refreshed: false,
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
if (!params.clientId?.trim() || !params.refreshToken?.trim()) {
|
|
172
|
-
throw new Error(
|
|
173
|
-
"Missing Google Meet OAuth credentials. Configure oauth.clientId and oauth.refreshToken, or pass --client-id and --refresh-token.",
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
const refreshed = await refreshGoogleMeetAccessToken({
|
|
177
|
-
clientId: params.clientId,
|
|
178
|
-
clientSecret: params.clientSecret,
|
|
179
|
-
refreshToken: params.refreshToken,
|
|
180
|
-
});
|
|
181
|
-
return {
|
|
182
|
-
accessToken: refreshed.accessToken,
|
|
183
|
-
expiresAt: refreshed.expiresAt,
|
|
184
|
-
refreshed: true,
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export function createGoogleMeetPkce() {
|
|
189
|
-
const { verifier, challenge } = generateHexPkceVerifierChallenge();
|
|
190
|
-
return { verifier, challenge };
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export function createGoogleMeetOAuthState(): string {
|
|
194
|
-
return generateOAuthState();
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export async function waitForGoogleMeetAuthCode(params: {
|
|
198
|
-
state: string;
|
|
199
|
-
manual: boolean;
|
|
200
|
-
timeoutMs: number;
|
|
201
|
-
authUrl: string;
|
|
202
|
-
promptInput: (message: string) => Promise<string>;
|
|
203
|
-
writeLine: (message: string) => void;
|
|
204
|
-
}): Promise<string> {
|
|
205
|
-
params.writeLine(`Open this URL in your browser:\n\n${params.authUrl}\n`);
|
|
206
|
-
if (params.manual) {
|
|
207
|
-
const input = await params.promptInput("Paste the full redirect URL here: ");
|
|
208
|
-
const parsed = parseOAuthCallbackInput(input, {
|
|
209
|
-
missingState: "Missing 'state' parameter. Paste the full redirect URL.",
|
|
210
|
-
invalidInput: "Paste the full redirect URL, not just the code.",
|
|
211
|
-
});
|
|
212
|
-
if ("error" in parsed) {
|
|
213
|
-
throw new Error(parsed.error);
|
|
214
|
-
}
|
|
215
|
-
if (parsed.state !== params.state) {
|
|
216
|
-
throw new Error("OAuth state mismatch - please try again");
|
|
217
|
-
}
|
|
218
|
-
return parsed.code;
|
|
219
|
-
}
|
|
220
|
-
const callback = await waitForLocalOAuthCallback({
|
|
221
|
-
expectedState: params.state,
|
|
222
|
-
timeoutMs: params.timeoutMs,
|
|
223
|
-
port: 8085,
|
|
224
|
-
callbackPath: "/oauth2callback",
|
|
225
|
-
redirectUri: GOOGLE_MEET_REDIRECT_URI,
|
|
226
|
-
successTitle: "Google Meet OAuth complete",
|
|
227
|
-
});
|
|
228
|
-
return callback.code;
|
|
229
|
-
}
|
package/src/realtime-node.ts
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
|
|
2
|
-
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
|
3
|
-
import type { PluginRuntime, RuntimeLogger } from "openclaw/plugin-sdk/plugin-runtime";
|
|
4
|
-
import {
|
|
5
|
-
createRealtimeVoiceBridgeSession,
|
|
6
|
-
type RealtimeVoiceBridgeSession,
|
|
7
|
-
type RealtimeVoiceProviderPlugin,
|
|
8
|
-
} from "openclaw/plugin-sdk/realtime-voice";
|
|
9
|
-
import {
|
|
10
|
-
consultOpenClawAgentForGoogleMeet,
|
|
11
|
-
GOOGLE_MEET_AGENT_CONSULT_TOOL_NAME,
|
|
12
|
-
resolveGoogleMeetRealtimeTools,
|
|
13
|
-
submitGoogleMeetConsultWorkingResponse,
|
|
14
|
-
} from "./agent-consult.js";
|
|
15
|
-
import type { GoogleMeetConfig } from "./config.js";
|
|
16
|
-
import {
|
|
17
|
-
resolveGoogleMeetRealtimeAudioFormat,
|
|
18
|
-
resolveGoogleMeetRealtimeProvider,
|
|
19
|
-
} from "./realtime.js";
|
|
20
|
-
import type { GoogleMeetChromeHealth } from "./transports/types.js";
|
|
21
|
-
|
|
22
|
-
export type ChromeNodeRealtimeAudioBridgeHandle = {
|
|
23
|
-
type: "node-command-pair";
|
|
24
|
-
providerId: string;
|
|
25
|
-
nodeId: string;
|
|
26
|
-
bridgeId: string;
|
|
27
|
-
speak: (instructions?: string) => void;
|
|
28
|
-
getHealth: () => GoogleMeetChromeHealth;
|
|
29
|
-
stop: () => Promise<void>;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
function asRecord(value: unknown): Record<string, unknown> {
|
|
33
|
-
return value && typeof value === "object" && !Array.isArray(value)
|
|
34
|
-
? (value as Record<string, unknown>)
|
|
35
|
-
: {};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function readString(value: unknown): string | undefined {
|
|
39
|
-
return typeof value === "string" && value.trim() ? value : undefined;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function startNodeRealtimeAudioBridge(params: {
|
|
43
|
-
config: GoogleMeetConfig;
|
|
44
|
-
fullConfig: OpenClawConfig;
|
|
45
|
-
runtime: PluginRuntime;
|
|
46
|
-
meetingSessionId: string;
|
|
47
|
-
nodeId: string;
|
|
48
|
-
bridgeId: string;
|
|
49
|
-
logger: RuntimeLogger;
|
|
50
|
-
providers?: RealtimeVoiceProviderPlugin[];
|
|
51
|
-
}): Promise<ChromeNodeRealtimeAudioBridgeHandle> {
|
|
52
|
-
let stopped = false;
|
|
53
|
-
let bridge: RealtimeVoiceBridgeSession | null = null;
|
|
54
|
-
let realtimeReady = false;
|
|
55
|
-
let lastInputAt: string | undefined;
|
|
56
|
-
let lastOutputAt: string | undefined;
|
|
57
|
-
let lastClearAt: string | undefined;
|
|
58
|
-
let lastInputBytes = 0;
|
|
59
|
-
let lastOutputBytes = 0;
|
|
60
|
-
let consecutiveInputErrors = 0;
|
|
61
|
-
let lastInputError: string | undefined;
|
|
62
|
-
let clearCount = 0;
|
|
63
|
-
const resolved = resolveGoogleMeetRealtimeProvider({
|
|
64
|
-
config: params.config,
|
|
65
|
-
fullConfig: params.fullConfig,
|
|
66
|
-
providers: params.providers,
|
|
67
|
-
});
|
|
68
|
-
const transcript: Array<{ role: "user" | "assistant"; text: string }> = [];
|
|
69
|
-
|
|
70
|
-
const stop = async () => {
|
|
71
|
-
if (stopped) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
stopped = true;
|
|
75
|
-
try {
|
|
76
|
-
bridge?.close();
|
|
77
|
-
} catch (error) {
|
|
78
|
-
params.logger.debug?.(
|
|
79
|
-
`[google-meet] node realtime bridge close ignored: ${formatErrorMessage(error)}`,
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
try {
|
|
83
|
-
await params.runtime.nodes.invoke({
|
|
84
|
-
nodeId: params.nodeId,
|
|
85
|
-
command: "googlemeet.chrome",
|
|
86
|
-
params: { action: "stop", bridgeId: params.bridgeId },
|
|
87
|
-
timeoutMs: 5_000,
|
|
88
|
-
});
|
|
89
|
-
} catch (error) {
|
|
90
|
-
params.logger.debug?.(
|
|
91
|
-
`[google-meet] node audio bridge stop ignored: ${formatErrorMessage(error)}`,
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
bridge = createRealtimeVoiceBridgeSession({
|
|
97
|
-
provider: resolved.provider,
|
|
98
|
-
providerConfig: resolved.providerConfig,
|
|
99
|
-
audioFormat: resolveGoogleMeetRealtimeAudioFormat(params.config),
|
|
100
|
-
instructions: params.config.realtime.instructions,
|
|
101
|
-
initialGreetingInstructions: params.config.realtime.introMessage,
|
|
102
|
-
triggerGreetingOnReady: false,
|
|
103
|
-
markStrategy: "ack-immediately",
|
|
104
|
-
tools: resolveGoogleMeetRealtimeTools(params.config.realtime.toolPolicy),
|
|
105
|
-
audioSink: {
|
|
106
|
-
isOpen: () => !stopped,
|
|
107
|
-
sendAudio: (audio) => {
|
|
108
|
-
lastOutputAt = new Date().toISOString();
|
|
109
|
-
lastOutputBytes += audio.byteLength;
|
|
110
|
-
void params.runtime.nodes
|
|
111
|
-
.invoke({
|
|
112
|
-
nodeId: params.nodeId,
|
|
113
|
-
command: "googlemeet.chrome",
|
|
114
|
-
params: {
|
|
115
|
-
action: "pushAudio",
|
|
116
|
-
bridgeId: params.bridgeId,
|
|
117
|
-
base64: Buffer.from(audio).toString("base64"),
|
|
118
|
-
},
|
|
119
|
-
timeoutMs: 5_000,
|
|
120
|
-
})
|
|
121
|
-
.catch((error) => {
|
|
122
|
-
params.logger.warn(
|
|
123
|
-
`[google-meet] node audio output failed: ${formatErrorMessage(error)}`,
|
|
124
|
-
);
|
|
125
|
-
void stop();
|
|
126
|
-
});
|
|
127
|
-
},
|
|
128
|
-
clearAudio: () => {
|
|
129
|
-
lastClearAt = new Date().toISOString();
|
|
130
|
-
clearCount += 1;
|
|
131
|
-
void params.runtime.nodes
|
|
132
|
-
.invoke({
|
|
133
|
-
nodeId: params.nodeId,
|
|
134
|
-
command: "googlemeet.chrome",
|
|
135
|
-
params: {
|
|
136
|
-
action: "clearAudio",
|
|
137
|
-
bridgeId: params.bridgeId,
|
|
138
|
-
},
|
|
139
|
-
timeoutMs: 5_000,
|
|
140
|
-
})
|
|
141
|
-
.catch((error) => {
|
|
142
|
-
params.logger.warn(
|
|
143
|
-
`[google-meet] node audio clear failed: ${formatErrorMessage(error)}`,
|
|
144
|
-
);
|
|
145
|
-
void stop();
|
|
146
|
-
});
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
onTranscript: (role, text, isFinal) => {
|
|
150
|
-
if (isFinal) {
|
|
151
|
-
transcript.push({ role, text });
|
|
152
|
-
if (transcript.length > 40) {
|
|
153
|
-
transcript.splice(0, transcript.length - 40);
|
|
154
|
-
}
|
|
155
|
-
params.logger.debug?.(`[google-meet] ${role}: ${text}`);
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
onToolCall: (event, session) => {
|
|
159
|
-
if (event.name !== GOOGLE_MEET_AGENT_CONSULT_TOOL_NAME) {
|
|
160
|
-
session.submitToolResult(event.callId || event.itemId, {
|
|
161
|
-
error: `Tool "${event.name}" not available`,
|
|
162
|
-
});
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
submitGoogleMeetConsultWorkingResponse(session, event.callId || event.itemId);
|
|
166
|
-
void consultOpenClawAgentForGoogleMeet({
|
|
167
|
-
config: params.config,
|
|
168
|
-
fullConfig: params.fullConfig,
|
|
169
|
-
runtime: params.runtime,
|
|
170
|
-
logger: params.logger,
|
|
171
|
-
meetingSessionId: params.meetingSessionId,
|
|
172
|
-
args: event.args,
|
|
173
|
-
transcript,
|
|
174
|
-
})
|
|
175
|
-
.then((result) => {
|
|
176
|
-
session.submitToolResult(event.callId || event.itemId, result);
|
|
177
|
-
})
|
|
178
|
-
.catch((error: Error) => {
|
|
179
|
-
session.submitToolResult(event.callId || event.itemId, {
|
|
180
|
-
error: formatErrorMessage(error),
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
},
|
|
184
|
-
onError: (error) => {
|
|
185
|
-
params.logger.warn(
|
|
186
|
-
`[google-meet] node realtime voice bridge failed: ${formatErrorMessage(error)}`,
|
|
187
|
-
);
|
|
188
|
-
void stop();
|
|
189
|
-
},
|
|
190
|
-
onClose: (reason) => {
|
|
191
|
-
realtimeReady = false;
|
|
192
|
-
if (reason === "error") {
|
|
193
|
-
void stop();
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
onReady: () => {
|
|
197
|
-
realtimeReady = true;
|
|
198
|
-
},
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
await bridge.connect();
|
|
202
|
-
|
|
203
|
-
void (async () => {
|
|
204
|
-
for (;;) {
|
|
205
|
-
if (stopped) {
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
try {
|
|
209
|
-
const raw = await params.runtime.nodes.invoke({
|
|
210
|
-
nodeId: params.nodeId,
|
|
211
|
-
command: "googlemeet.chrome",
|
|
212
|
-
params: { action: "pullAudio", bridgeId: params.bridgeId, timeoutMs: 250 },
|
|
213
|
-
timeoutMs: 2_000,
|
|
214
|
-
});
|
|
215
|
-
const result = asRecord(asRecord(raw).payload ?? raw);
|
|
216
|
-
consecutiveInputErrors = 0;
|
|
217
|
-
lastInputError = undefined;
|
|
218
|
-
const base64 = readString(result.base64);
|
|
219
|
-
if (base64) {
|
|
220
|
-
const audio = Buffer.from(base64, "base64");
|
|
221
|
-
lastInputAt = new Date().toISOString();
|
|
222
|
-
lastInputBytes += audio.byteLength;
|
|
223
|
-
bridge?.sendAudio(audio);
|
|
224
|
-
}
|
|
225
|
-
if (result.closed === true) {
|
|
226
|
-
await stop();
|
|
227
|
-
}
|
|
228
|
-
} catch (error) {
|
|
229
|
-
if (!stopped) {
|
|
230
|
-
const message = formatErrorMessage(error);
|
|
231
|
-
consecutiveInputErrors += 1;
|
|
232
|
-
lastInputError = message;
|
|
233
|
-
params.logger.warn(
|
|
234
|
-
`[google-meet] node audio input failed (${consecutiveInputErrors}/5): ${message}`,
|
|
235
|
-
);
|
|
236
|
-
if (consecutiveInputErrors >= 5 || /unknown bridgeId|bridge is not open/i.test(message)) {
|
|
237
|
-
await stop();
|
|
238
|
-
} else {
|
|
239
|
-
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
})();
|
|
245
|
-
|
|
246
|
-
return {
|
|
247
|
-
type: "node-command-pair",
|
|
248
|
-
providerId: resolved.provider.id,
|
|
249
|
-
nodeId: params.nodeId,
|
|
250
|
-
bridgeId: params.bridgeId,
|
|
251
|
-
speak: (instructions) => {
|
|
252
|
-
bridge?.triggerGreeting(instructions);
|
|
253
|
-
},
|
|
254
|
-
getHealth: () => ({
|
|
255
|
-
providerConnected: bridge?.bridge.isConnected() ?? false,
|
|
256
|
-
realtimeReady,
|
|
257
|
-
audioInputActive: lastInputBytes > 0,
|
|
258
|
-
audioOutputActive: lastOutputBytes > 0,
|
|
259
|
-
lastInputAt,
|
|
260
|
-
lastOutputAt,
|
|
261
|
-
lastClearAt,
|
|
262
|
-
lastInputBytes,
|
|
263
|
-
lastOutputBytes,
|
|
264
|
-
consecutiveInputErrors,
|
|
265
|
-
lastInputError,
|
|
266
|
-
clearCount,
|
|
267
|
-
bridgeClosed: stopped,
|
|
268
|
-
}),
|
|
269
|
-
stop,
|
|
270
|
-
};
|
|
271
|
-
}
|