omni-notify-mcp 1.3.308 → 1.3.310
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/gateway/sessionDriver.js +2 -2
- package/dist/shared/agentSession.js +1 -1
- package/dist/shared/webhost/bullseyeWebHost.js +44 -11
- package/dist/shared/webhost/webviewShim.js +63 -4
- package/package.json +1 -1
- package/dist/googlehome/foyer-client.js +0 -210
- package/dist/googlehome/foyer-codec.js +0 -318
- package/dist/googlehome/gpsoauth.js +0 -119
- package/dist/googlehome/index.js +0 -267
- package/scripts/shared/ownerGuard.cs +0 -665
- package/scripts/shared/ownerGuard.ps1 +0 -31
- /package/scripts/shared/{ownerGuard.js → ownerGuard.cjs} +0 -0
package/dist/googlehome/index.js
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
// Google Home over MCP: reads and controls Meni's Google Home devices and runs his routines, on the
|
|
2
|
-
// SAME agent-gateway door (`/mcp`, port 7470) and behind the same bearer/passkey/OAuth auth as the
|
|
3
|
-
// `agent_*` tools — so ChatGPT's voice mode drives them exactly as it drives the agent sessions.
|
|
4
|
-
//
|
|
5
|
-
// The device/room/routine layer is ported from coredevices/pebble-plugins `googlehome/src/server.ts`
|
|
6
|
-
// (its Kotlin `GoogleHomeMcpServer` + `DeviceResolver` origin). Lock/unlock and the passcode are
|
|
7
|
-
// deliberately ABSENT: an MCP door that unlocks the house is Meni's decision, never a default.
|
|
8
|
-
//
|
|
9
|
-
// The device list, the command codec and the sign-in all ride Google's PRIVATE app API (the foyer
|
|
10
|
-
// interface), reverse engineered and undocumented; Google can change it without notice, and no
|
|
11
|
-
// documented Google path covers non-Nest lights, plugs or speakers.
|
|
12
|
-
import { z } from "zod";
|
|
13
|
-
import { effectiveType } from "./foyer-codec.js";
|
|
14
|
-
import { FoyerAuth, FoyerClient, GoogleHomeError } from "./foyer-client.js";
|
|
15
|
-
import { FoyerAuthError, GpsOAuth } from "./gpsoauth.js";
|
|
16
|
-
import { googleHomeCredential } from "../notify.js";
|
|
17
|
-
/** Every tool's answer is JSON text, as the gateway's `agent_*` tools do. */
|
|
18
|
-
const answer = (value) => ({ content: [{ type: "text", text: JSON.stringify(value, null, 2) }] });
|
|
19
|
-
/** A refused act (a known Google Home failure: not signed in, no device matched, an API/HTTP error)
|
|
20
|
-
* is the tool's own error result carrying its reason; anything else is a bug and rethrows to the SDK,
|
|
21
|
-
* which answers a protocol error rather than a mask. */
|
|
22
|
-
function act(run) {
|
|
23
|
-
return Promise.resolve()
|
|
24
|
-
.then(run)
|
|
25
|
-
.then(answer)
|
|
26
|
-
.catch((err) => {
|
|
27
|
-
if (err instanceof GoogleHomeError || err instanceof FoyerAuthError) {
|
|
28
|
-
return { content: [{ type: "text", text: err.message }], isError: true };
|
|
29
|
-
}
|
|
30
|
-
throw err;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
const NOT_SIGNED_IN = "Google Home is not signed in on this machine. Run `node scripts/googlehome-signin.mjs` once in a " +
|
|
34
|
-
"terminal and sign in with the Google account that owns your home; the one-time token is exchanged " +
|
|
35
|
-
"for a long-lived master token and stored in the notify secrets file.";
|
|
36
|
-
/** The sign-in secret resolved fresh: a sign-in that just happened is seen by the next tool call, no restart. */
|
|
37
|
-
function client() {
|
|
38
|
-
const cred = googleHomeCredential();
|
|
39
|
-
if (cred == null)
|
|
40
|
-
throw new GoogleHomeError(NOT_SIGNED_IN);
|
|
41
|
-
return new FoyerClient(new FoyerAuth(cred.masterToken, cred.androidId, new GpsOAuth()));
|
|
42
|
-
}
|
|
43
|
-
function norm(s) {
|
|
44
|
-
const t = s?.trim().toLowerCase();
|
|
45
|
-
return t && t !== "" ? t : null;
|
|
46
|
-
}
|
|
47
|
-
function typeMatches(deviceType, want) {
|
|
48
|
-
const suffix = deviceType.split(".").pop()?.toLowerCase() ?? "";
|
|
49
|
-
return suffix === want || deviceType.toLowerCase() === want;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Natural requests often append a device kind to a custom Google Home name: "driveway lights" for a
|
|
53
|
-
* light-capable device actually named "driveway". Only leading articles and trailing kind words that
|
|
54
|
-
* fit the action's required capability are stripped — deliberately no general fuzzy matching, which
|
|
55
|
-
* could control the wrong device.
|
|
56
|
-
*/
|
|
57
|
-
const SELECTOR_KIND_WORDS = {
|
|
58
|
-
on_off: new Set(["light", "lights", "lamp", "lamps", "bulb", "bulbs", "switch", "switches", "outlet", "outlets", "plug", "plugs", "speaker", "speakers"]),
|
|
59
|
-
brightness: new Set(["light", "lights", "lamp", "lamps", "bulb", "bulbs"]),
|
|
60
|
-
color_temperature: new Set(["light", "lights", "lamp", "lamps", "bulb", "bulbs"]),
|
|
61
|
-
color: new Set(["light", "lights", "lamp", "lamps", "bulb", "bulbs"]),
|
|
62
|
-
volume: new Set(["speaker", "speakers"]),
|
|
63
|
-
lock: new Set(["lock", "locks"]),
|
|
64
|
-
thermostat: new Set(["thermostat", "thermostats"]),
|
|
65
|
-
media_transport: new Set(["speaker", "speakers", "player", "players", "tv", "tvs", "display", "displays"]),
|
|
66
|
-
};
|
|
67
|
-
const SELECTOR_LEADING_WORDS = new Set(["the", "my"]);
|
|
68
|
-
function selectorNameAliases(wantName, requiredCap) {
|
|
69
|
-
const original = wantName.split(/\s+/).filter((word) => word !== "");
|
|
70
|
-
if (original.length < 2)
|
|
71
|
-
return [];
|
|
72
|
-
const aliases = [];
|
|
73
|
-
const kindWords = SELECTOR_KIND_WORDS[requiredCap];
|
|
74
|
-
const suffixStripped = [...original];
|
|
75
|
-
while (suffixStripped.length > 1 && kindWords.has(suffixStripped[suffixStripped.length - 1])) {
|
|
76
|
-
suffixStripped.pop();
|
|
77
|
-
aliases.push(suffixStripped.join(" "));
|
|
78
|
-
}
|
|
79
|
-
const leadingStripped = [...original];
|
|
80
|
-
while (leadingStripped.length > 1 && SELECTOR_LEADING_WORDS.has(leadingStripped[0])) {
|
|
81
|
-
leadingStripped.shift();
|
|
82
|
-
aliases.push(leadingStripped.join(" "));
|
|
83
|
-
}
|
|
84
|
-
while (leadingStripped.length > 1 && kindWords.has(leadingStripped[leadingStripped.length - 1])) {
|
|
85
|
-
leadingStripped.pop();
|
|
86
|
-
aliases.push(leadingStripped.join(" "));
|
|
87
|
-
}
|
|
88
|
-
return [
|
|
89
|
-
...new Set(aliases.filter((alias) => {
|
|
90
|
-
const words = alias.split(/\s+/);
|
|
91
|
-
return alias !== "" && alias !== wantName && words.some((word) => !SELECTOR_LEADING_WORDS.has(word) && !kindWords.has(word));
|
|
92
|
-
})),
|
|
93
|
-
];
|
|
94
|
-
}
|
|
95
|
-
function matchExact(devices, wantedNames) {
|
|
96
|
-
for (const wanted of wantedNames) {
|
|
97
|
-
const exact = devices.filter((device) => device.name.trim().toLowerCase() === wanted);
|
|
98
|
-
if (exact.length > 0)
|
|
99
|
-
return exact;
|
|
100
|
-
}
|
|
101
|
-
return [];
|
|
102
|
-
}
|
|
103
|
-
function matchSubstring(devices, wantedNames) {
|
|
104
|
-
for (const wanted of wantedNames) {
|
|
105
|
-
const substring = devices.filter((device) => device.name.trim().toLowerCase().includes(wanted));
|
|
106
|
-
if (substring.length > 0)
|
|
107
|
-
return substring;
|
|
108
|
-
}
|
|
109
|
-
return [];
|
|
110
|
-
}
|
|
111
|
-
function describeSelector(sel) {
|
|
112
|
-
const parts = [
|
|
113
|
-
sel.name && sel.name.trim() !== "" ? `name="${sel.name}"` : null,
|
|
114
|
-
sel.room && sel.room.trim() !== "" ? `room="${sel.room}"` : null,
|
|
115
|
-
sel.type && sel.type.trim() !== "" ? `type="${sel.type}"` : null,
|
|
116
|
-
].filter((p) => p != null);
|
|
117
|
-
return parts.length === 0 ? "(no filters)" : parts.join(", ");
|
|
118
|
-
}
|
|
119
|
-
function nearNames(sel, devices, limit = 12) {
|
|
120
|
-
const wantRoom = norm(sel.room);
|
|
121
|
-
const wantType = norm(sel.type);
|
|
122
|
-
const wantNameTokens = (norm(sel.name) ?? "").split(/\s+/).filter((t) => t !== "");
|
|
123
|
-
const relaxed = devices.filter((d) => (wantRoom != null && d.roomName?.trim().toLowerCase().includes(wantRoom) === true) ||
|
|
124
|
-
(wantType != null && typeMatches(effectiveType(d), wantType)) ||
|
|
125
|
-
(wantNameTokens.length > 0 && wantNameTokens.some((t) => d.name.toLowerCase().includes(t))));
|
|
126
|
-
const pool = relaxed.length > 0 ? relaxed : devices;
|
|
127
|
-
return [...new Set(pool.map((d) => d.name))].slice(0, limit);
|
|
128
|
-
}
|
|
129
|
-
async function resolve(foyer, sel, requiredCap) {
|
|
130
|
-
if (norm(sel.name) == null && norm(sel.room) == null && norm(sel.type) == null) {
|
|
131
|
-
throw new GoogleHomeError('Provide at least one selector: name, room, and/or type (e.g. type="light" for all lights, ' +
|
|
132
|
-
'or room="kitchen" + type="light" for the kitchen lights).');
|
|
133
|
-
}
|
|
134
|
-
const { devices } = await foyer.getHomeGraph();
|
|
135
|
-
const wantName = norm(sel.name);
|
|
136
|
-
const wantRoom = norm(sel.room);
|
|
137
|
-
const wantType = norm(sel.type);
|
|
138
|
-
// Room matches EXACTLY; type matches the type suffix. AND-combined.
|
|
139
|
-
const scoped = devices.filter((d) => (wantRoom == null || d.roomName?.trim().toLowerCase() === wantRoom) &&
|
|
140
|
-
(wantType == null || typeMatches(effectiveType(d), wantType)));
|
|
141
|
-
let matches;
|
|
142
|
-
if (wantName == null) {
|
|
143
|
-
matches = scoped;
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
matches = matchExact(scoped, [wantName]);
|
|
147
|
-
if (matches.length === 0) {
|
|
148
|
-
const aliases = selectorNameAliases(wantName, requiredCap);
|
|
149
|
-
matches = matchExact(scoped, aliases);
|
|
150
|
-
if (matches.length === 0) {
|
|
151
|
-
const capable = scoped.filter((device) => device.capabilities.has(requiredCap));
|
|
152
|
-
matches = matchSubstring(capable, aliases);
|
|
153
|
-
}
|
|
154
|
-
if (matches.length === 0)
|
|
155
|
-
matches = matchSubstring(scoped, [wantName]);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (matches.length === 0) {
|
|
159
|
-
const near = nearNames(sel, devices);
|
|
160
|
-
const known = near.length === 0 ? "No devices are known." : `Closest known devices: ${near.map((n) => `"${n}"`).join(", ")}.`;
|
|
161
|
-
throw new GoogleHomeError(`No devices matched selector ${describeSelector(sel)}. ${known} ` +
|
|
162
|
-
"Use googlehome_list_devices to see every device with its room, type and capabilities.");
|
|
163
|
-
}
|
|
164
|
-
return matches;
|
|
165
|
-
}
|
|
166
|
-
// -------------------------------------------------------------------------------------------------
|
|
167
|
-
// JSON projection
|
|
168
|
-
// -------------------------------------------------------------------------------------------------
|
|
169
|
-
function stateToJson(s) {
|
|
170
|
-
return {
|
|
171
|
-
id: s.id,
|
|
172
|
-
online: s.online,
|
|
173
|
-
on_off: s.onOff,
|
|
174
|
-
brightness_pct: s.brightnessPct,
|
|
175
|
-
color_temperature_k: s.colorTemperatureK,
|
|
176
|
-
volume_pct: s.volumePct,
|
|
177
|
-
muted: s.muted,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
function deviceToJson(d, state) {
|
|
181
|
-
const et = effectiveType(d);
|
|
182
|
-
const out = { id: d.id, name: d.name, type: et };
|
|
183
|
-
if (d.assignedType != null && d.assignedType !== d.type)
|
|
184
|
-
out["hardware_type"] = d.type;
|
|
185
|
-
out["capabilities"] = [...d.capabilities];
|
|
186
|
-
out["room_name"] = d.roomName;
|
|
187
|
-
out["online"] = state?.online ?? null;
|
|
188
|
-
out["on_off"] = state?.onOff ?? null;
|
|
189
|
-
return out;
|
|
190
|
-
}
|
|
191
|
-
function resultRow(id, name, ok, state, error) {
|
|
192
|
-
const row = { id, name, ok };
|
|
193
|
-
if (state)
|
|
194
|
-
row["state"] = stateToJson(state);
|
|
195
|
-
if (error)
|
|
196
|
-
row["error"] = error;
|
|
197
|
-
return row;
|
|
198
|
-
}
|
|
199
|
-
// -------------------------------------------------------------------------------------------------
|
|
200
|
-
// Control plumbing
|
|
201
|
-
// -------------------------------------------------------------------------------------------------
|
|
202
|
-
const agent = (d) => d.agentId ?? "";
|
|
203
|
-
const partner = (d) => d.partnerDeviceId ?? "";
|
|
204
|
-
async function applyControl(args, requiredCap, capLabel, action) {
|
|
205
|
-
const foyer = client();
|
|
206
|
-
const devices = await resolve(foyer, args, requiredCap);
|
|
207
|
-
const rows = [];
|
|
208
|
-
for (const d of devices) {
|
|
209
|
-
if (!d.capabilities.has(requiredCap)) {
|
|
210
|
-
rows.push(resultRow(d.id, d.name, false, undefined, `skipped: does not support ${capLabel}`));
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
try {
|
|
214
|
-
rows.push(resultRow(d.id, d.name, true, await action(foyer, d)));
|
|
215
|
-
}
|
|
216
|
-
catch (e) {
|
|
217
|
-
rows.push(resultRow(d.id, d.name, false, undefined, e instanceof Error ? e.message : String(e)));
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return { matched: devices.length, results: rows };
|
|
221
|
-
}
|
|
222
|
-
const SELECTOR_KEYS = {
|
|
223
|
-
name: z.string().optional().describe('Device name to match (exact preferred, then case-insensitive substring); a trailing kind like "lights" is tolerated.'),
|
|
224
|
-
room: z.string().optional().describe('Room name to match (case-insensitive substring), e.g. "kitchen".'),
|
|
225
|
-
type: z.string().optional().describe("Device type suffix: light, speaker, outlet, switch, thermostat."),
|
|
226
|
-
};
|
|
227
|
-
function selectorFrom(a) {
|
|
228
|
-
return { name: a.name, room: a.room, type: a.type };
|
|
229
|
-
}
|
|
230
|
-
// -------------------------------------------------------------------------------------------------
|
|
231
|
-
// Tool registration
|
|
232
|
-
// -------------------------------------------------------------------------------------------------
|
|
233
|
-
/**
|
|
234
|
-
* Register the Google Home tools on the agent-gateway MCP server, beside the `agent_*` tools.
|
|
235
|
-
* Read tools enumerate and read; control tools take a selector, apply to EVERY capable match, and
|
|
236
|
-
* return per-device {id,name,ok,state|error}. There is no add/delete surface.
|
|
237
|
-
*/
|
|
238
|
-
export function registerGoogleHomeTools(server) {
|
|
239
|
-
server.tool("googlehome_list_devices", "List every Google Home device across all homes with its room, type, capabilities (on_off, brightness, color_temperature, color, volume, thermostat, media_transport) and live online/on-off state. Read-only. Use it to see the names/rooms/types the control tools' selectors target.", {}, () => act(async () => {
|
|
240
|
-
const foyer = client();
|
|
241
|
-
const { devices } = await foyer.getHomeGraph();
|
|
242
|
-
let stateById = new Map();
|
|
243
|
-
if (devices.length > 0) {
|
|
244
|
-
stateById = new Map((await foyer.getTraits(devices.map((d) => d.id))).map((s) => [s.id, s]));
|
|
245
|
-
}
|
|
246
|
-
return devices.map((d) => deviceToJson(d, stateById.get(d.id)));
|
|
247
|
-
}));
|
|
248
|
-
server.tool("googlehome_get_device_state", "Get the live state (online, on/off, brightness, color temperature, volume, mute) for one or more devices by id. Read-only.", { device_ids: z.array(z.string()).describe("Device ids to read state for") }, ({ device_ids }) => act(async () => (await client().getTraits(device_ids)).map(stateToJson)));
|
|
249
|
-
server.tool("googlehome_turn_on", 'Turn on devices. Scope with name/room/type: name="Corner Lamp" for one, type="light" for all lights, room="kitchen" + type="light" for the kitchen lights. Applies to every matching on/off device.', SELECTOR_KEYS, (a) => act(() => applyControl(selectorFrom(a), "on_off", "on/off", (f, d) => f.setOnOff(d.id, agent(d), partner(d), true))));
|
|
250
|
-
server.tool("googlehome_turn_off", 'Turn off devices. Scope with name/room/type, e.g. type="light" for all lights.', SELECTOR_KEYS, (a) => act(() => applyControl(selectorFrom(a), "on_off", "on/off", (f, d) => f.setOnOff(d.id, agent(d), partner(d), false))));
|
|
251
|
-
server.tool("googlehome_set_brightness", 'Set brightness (0-100%) on lights. Scope with name/room/type, e.g. room="bedroom" + type="light", brightness_pct=40.', { ...SELECTOR_KEYS, brightness_pct: z.number().describe("Brightness 0-100 (clamped)") }, (a) => act(() => applyControl(selectorFrom(a), "brightness", "brightness", (f, d) => f.setBrightness(d.id, agent(d), partner(d), a.brightness_pct))));
|
|
252
|
-
server.tool("googlehome_set_color_temperature", "Set white color temperature in Kelvin (warm ~2700, cool ~6500) on color-temperature lights. Scope with name/room/type, e.g. name=\"Desk Light\", kelvin=4000.", { ...SELECTOR_KEYS, kelvin: z.number().describe("Color temperature in Kelvin, e.g. 2700-6500") }, (a) => act(() => applyControl(selectorFrom(a), "color_temperature", "color temperature", (f, d) => f.setColorTemperature(d.id, agent(d), partner(d), a.kelvin))));
|
|
253
|
-
server.tool("googlehome_set_volume", 'Set volume (0-100%) on speakers. Scope with name/room/type, e.g. name="Living Room Speaker" volume_pct=30.', { ...SELECTOR_KEYS, volume_pct: z.number().describe("Volume 0-100 (clamped)") }, (a) => act(() => applyControl(selectorFrom(a), "volume", "volume", (f, d) => f.setVolume(d.id, agent(d), partner(d), a.volume_pct))));
|
|
254
|
-
server.tool("googlehome_set_muted", 'Mute or unmute speakers. Scope with name/room/type, e.g. type="speaker" muted=true.', { ...SELECTOR_KEYS, muted: z.boolean().describe("true = muted, false = unmuted") }, (a) => act(() => applyControl(selectorFrom(a), "volume", "volume/mute", (f, d) => f.setMuted(d.id, agent(d), partner(d), a.muted))));
|
|
255
|
-
server.tool("googlehome_list_routines", "List the home's Google Home routines: name and whether it can be started on demand (manually_runnable). Read-only. Use before googlehome_run_routine.", {}, () => act(async () => (await client().listAutomations()).map((r) => ({ id: r.id, name: r.name, manually_runnable: r.manuallyRunnable }))));
|
|
256
|
-
server.tool("googlehome_run_routine", 'Run a Google Home routine by name, e.g. name="Movie Night". Only manually-runnable routines can be started on demand. This runs the routine\'s EXISTING actions; it never creates or deletes anything.', { name: z.string().describe("The routine's name (case-insensitive; exact preferred)") }, ({ name }) => act(async () => {
|
|
257
|
-
const wanted = name.trim();
|
|
258
|
-
const foyer = client();
|
|
259
|
-
const routines = await foyer.listAutomations();
|
|
260
|
-
const lower = wanted.toLowerCase();
|
|
261
|
-
const match = routines.find((r) => r.name.trim().toLowerCase() === lower) ?? routines.find((r) => r.name.trim().toLowerCase().includes(lower));
|
|
262
|
-
if (match == null) {
|
|
263
|
-
throw new GoogleHomeError(`No routine named '${wanted}'. Available: ${routines.map((r) => `"${r.name}"`).join(", ")}`);
|
|
264
|
-
}
|
|
265
|
-
return { name: match.name, id: match.id, ok: await foyer.runAutomation(match) };
|
|
266
|
-
}));
|
|
267
|
-
}
|