File size: 8,614 Bytes
e18726e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | import type { Command } from "commander";
import type { OpenClawPluginApi } from "../plugins/plugin-api.types.js";
import type { OpenClawPluginCliRootCommandDescriptor } from "../plugins/plugin-registration.types.js";
import { createLazyRuntimeModule } from "../shared/lazy-runtime.js";
import { createMeetingRealtimeEngineBindings } from "./agent-consult.js";
import {
createMeetingChromeTransport,
type MeetingChromeTransportConfig,
type MeetingChromeTransportOptions,
} from "./chrome-transport.js";
import { createMeetingConfiguredNodeHost } from "./configured-node-host.js";
import { isMeetingRealtimeRouteReady, isMeetingTalkBackMode } from "./meeting-modes.js";
import { createMeetingBrowserNodeInvokePolicy } from "./node-invoke-policy.js";
import type { MeetingPluginConfig } from "./plugin-config.js";
import {
createMeetingPluginEntryOptions,
type MeetingJoinRequest,
type MeetingPluginConfig as MeetingEntryConfig,
type MeetingPluginEntryOptions,
type MeetingPluginRuntime,
} from "./plugin-entry.js";
import { startMeetingAgentRealtimeEngine } from "./realtime-agent-engine.js";
import { startMeetingRealtimeEngine } from "./realtime-engine.js";
import { createLocalMeetingRealtimeAudioTransport } from "./realtime-local-audio-transport.js";
import { createNodeMeetingRealtimeAudioTransport } from "./realtime-node-audio-transport.js";
import type { MeetingProbeContext } from "./runtime-probes.js";
import type {
MeetingBrowserHealth,
MeetingBrowserTab,
MeetingPluginChromeHealth,
MeetingPluginJoinRequest,
MeetingPluginJoinResult,
MeetingPluginSession,
MeetingTranscriptSnapshot,
} from "./session-types.js";
type MeetingPluginShellPlatform = {
browserLabel: string;
displayName: string;
id: string;
nodeCommandName: string;
session: { idPrefix: string };
urls: {
validateAndNormalize(input: unknown): string;
normalizeForReuse(url: string | undefined): string | undefined;
};
};
type MeetingPluginNodeHostOptions = {
browserPageName: string;
defaultAudioInputCommand: readonly string[];
defaultAudioOutputCommand: readonly string[];
meetingLabel: string;
platform: MeetingPluginShellPlatform;
sharePrerequisiteDeadline: boolean;
};
export function createMeetingPluginNodeHostHandler(options: MeetingPluginNodeHostOptions) {
const platform = options.platform;
return createMeetingConfiguredNodeHost({
...options,
commandName: platform.nodeCommandName,
displayName: platform.displayName,
browserLabel: platform.browserLabel,
bridgeIdPrefix: `${platform.session.idPrefix}_node_`,
talkBackModes: new Set(["agent", "bidi"]),
agentMode: "agent",
defaultAudio: {
backend: "auto",
bufferBytes: 4_096,
format: "pcm16-24khz",
},
normalizeUrl: (value) => platform.urls.validateAndNormalize(value),
normalizeMeetingKey: (value) => platform.urls.normalizeForReuse(value),
browser: {
application: "Google Chrome",
buildProfileArgs: (profile) => ["--args", `--profile-directory=${profile}`],
openedStatus: "chrome-opened",
openedNotes: [
`${options.browserPageName} page control is handled by OpenClaw browser automation when using chrome-node.`,
],
},
});
}
export function createMeetingPluginNodeInvokePolicy(
config: { chrome: Parameters<typeof createMeetingBrowserNodeInvokePolicy>[0]["start"] },
options: { deniedCode: string; platform: MeetingPluginShellPlatform },
) {
const platform = options.platform;
return createMeetingBrowserNodeInvokePolicy({
commandName: platform.nodeCommandName,
displayName: platform.displayName,
deniedCode: options.deniedCode,
supportedModes: new Set(["agent", "bidi", "transcribe"]),
normalizeUrl: (value) => platform.urls.validateAndNormalize(value),
useConfiguredSetupCommands: true,
start: config.chrome,
});
}
export function createMeetingChromeRuntimeBindings() {
return {
createBindings: createMeetingRealtimeEngineBindings,
createLocalAudioTransport: createLocalMeetingRealtimeAudioTransport,
createNodeAudioTransport: createNodeMeetingRealtimeAudioTransport,
startAgentRealtimeEngine: startMeetingAgentRealtimeEngine,
startRealtimeEngine: startMeetingRealtimeEngine,
};
}
export function createMeetingPluginChromeTransport<
Mode extends string,
Health extends MeetingBrowserHealth,
Transcript extends MeetingTranscriptSnapshot,
>(
options: Omit<
MeetingChromeTransportOptions<Mode, Health, Transcript>,
"browserNodeAdapter" | "isRealtimeRouteReady" | "isTalkBackMode" | "nodeCommandName"
>,
) {
return createMeetingChromeTransport<MeetingChromeTransportConfig, Mode, Health, Transcript>({
...options,
browserNodeAdapter: options.platform,
isRealtimeRouteReady: isMeetingRealtimeRouteReady,
isTalkBackMode: isMeetingTalkBackMode,
nodeCommandName: options.platform.nodeCommandName,
});
}
type MeetingPluginShellEntryOptions<
Config extends MeetingEntryConfig,
Request extends MeetingJoinRequest,
Runtime extends MeetingPluginRuntime<Request>,
> = Omit<
MeetingPluginEntryOptions<Config, Request, Runtime>,
| "cap"
| "createRuntime"
| "description"
| "disabledMessage"
| "gatewayMethodPrefix"
| "id"
| "name"
| "nodeCommand"
| "normalizeUrl"
| "registerCli"
| "toolDescription"
| "toolLabel"
| "toolName"
| "transcriptSource"
| "unknownActionMessage"
> & {
cli: {
descriptor: OpenClawPluginCliRootCommandDescriptor;
load(): Promise<(params: { program: Command; config: Config }) => void>;
};
browserGuestLabel: string;
platform: MeetingPluginShellPlatform;
runtime: new (params: {
config: Config;
fullConfig: OpenClawPluginApi["config"];
logger: OpenClawPluginApi["logger"];
runtime: OpenClawPluginApi["runtime"];
}) => Runtime;
transcriptSource: { aliases?: readonly string[]; id: string };
};
export function createMeetingPluginShellEntry<
Config extends MeetingEntryConfig,
Request extends MeetingJoinRequest,
Runtime extends MeetingPluginRuntime<Request>,
>(options: MeetingPluginShellEntryOptions<Config, Request, Runtime>) {
const id = options.platform.id;
const methodPrefix = id.replaceAll("-", "");
const toolName = id.replaceAll("-", "_");
const loadCli = createLazyRuntimeModule(() => options.cli.load());
return createMeetingPluginEntryOptions<Config, Request, Runtime>({
...options,
id,
name: options.platform.displayName,
cap: id,
description: `Join ${options.platform.displayName} as a Chrome browser guest`,
disabledMessage: `${options.platform.displayName} plugin disabled in plugin config`,
gatewayMethodPrefix: methodPrefix,
nodeCommand: options.platform.nodeCommandName,
normalizeUrl: (value) => options.platform.urls.validateAndNormalize(value),
toolDescription: `Join and manage ${options.browserGuestLabel} browser guests. Guest admission, tenant sign-in, and media permissions may require manual action in the OpenClaw Chrome profile.`,
toolLabel: options.platform.displayName,
toolName,
transcriptSource: { ...options.transcriptSource, name: options.platform.displayName },
unknownActionMessage: `unknown ${toolName} action`,
createRuntime: ({ api, config }) =>
new options.runtime({
config,
fullConfig: api.config,
runtime: api.runtime,
logger: api.logger,
}),
registerCli: (api, config) => {
api.registerCli(async ({ program }) => (await loadCli())({ program, config }), {
commands: [options.cli.descriptor.name],
// Share the metadata descriptor so help and runtime output policy cannot drift.
descriptors: [options.cli.descriptor],
});
},
});
}
export function createMeetingPluginTypes<
Config extends MeetingPluginConfig,
Transport extends string,
Mode extends string,
ManualReason extends string,
SpeechBlockedReason extends string,
ExtraHealth extends object = object,
>() {
type Health = MeetingPluginChromeHealth<ManualReason, SpeechBlockedReason> & ExtraHealth;
type Request = MeetingPluginJoinRequest<Transport, Mode>;
type Session = MeetingPluginSession<Transport, Mode, Health>;
return null as unknown as {
BrowserTab: MeetingBrowserTab;
ChromeHealth: Health;
JoinRequest: Request;
JoinResult: MeetingPluginJoinResult<Session>;
ProbeContext: MeetingProbeContext<
Config & { defaultMode: Mode },
Mode,
Transport,
Health,
Session,
Request
>;
Session: Session;
TranscriptSnapshot: MeetingTranscriptSnapshot;
};
}
|