@openclaw/facetime 2026.11.3 → 2026.11.5-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.
Files changed (111) hide show
  1. package/dist/.setup/{setup-DMPG615Z.mjs → setup-D3xHzHpV.mjs} +52 -99
  2. package/dist/.source-module-urls/38481bccca5fbb406e50ac928748f9f04f5a6cf5623980901b3cebc6ee82dfb6.json +1 -0
  3. package/dist/index.js +9 -22
  4. package/dist/runtime-api.js +225 -339
  5. package/docs/phase1-verification.md +1 -1
  6. package/index.ts +13 -20
  7. package/node_modules/typebox/build/format/duration.d.mts +2 -2
  8. package/node_modules/typebox/build/format/duration.mjs +2 -2
  9. package/node_modules/typebox/build/format/idn_email.d.mts +1 -0
  10. package/node_modules/typebox/build/format/idn_email.mjs +1 -0
  11. package/node_modules/typebox/build/format/idn_hostname.d.mts +1 -1
  12. package/node_modules/typebox/build/format/idn_hostname.mjs +1 -1
  13. package/node_modules/typebox/build/format/ipv4.d.mts +2 -2
  14. package/node_modules/typebox/build/format/ipv4.mjs +2 -2
  15. package/node_modules/typebox/build/format/ipv6.d.mts +1 -1
  16. package/node_modules/typebox/build/format/ipv6.mjs +1 -1
  17. package/node_modules/typebox/build/format/relative_json_pointer.d.mts +2 -2
  18. package/node_modules/typebox/build/format/relative_json_pointer.mjs +2 -2
  19. package/node_modules/typebox/build/schema/build.mjs +1 -0
  20. package/node_modules/typebox/build/schema/engine/_unique.d.mts +4 -2
  21. package/node_modules/typebox/build/schema/engine/_unique.mjs +7 -3
  22. package/node_modules/typebox/build/schema/engine/additionalItems.mjs +3 -3
  23. package/node_modules/typebox/build/schema/engine/additionalProperties.d.mts +0 -3
  24. package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +15 -17
  25. package/node_modules/typebox/build/schema/engine/contains.mjs +3 -3
  26. package/node_modules/typebox/build/schema/engine/index.d.mts +1 -0
  27. package/node_modules/typebox/build/schema/engine/index.mjs +1 -0
  28. package/node_modules/typebox/build/schema/engine/items.mjs +7 -4
  29. package/node_modules/typebox/build/schema/engine/maxContains.mjs +2 -2
  30. package/node_modules/typebox/build/schema/engine/minContains.mjs +3 -3
  31. package/node_modules/typebox/build/schema/engine/oneOf.mjs +2 -2
  32. package/node_modules/typebox/build/schema/engine/patternProperties.mjs +2 -2
  33. package/node_modules/typebox/build/schema/engine/propertyNames.mjs +2 -2
  34. package/node_modules/typebox/build/schema/engine/unevaluatedItems.mjs +2 -2
  35. package/node_modules/typebox/build/schema/engine/unevaluatedProperties.mjs +2 -2
  36. package/node_modules/typebox/build/system/hashing/hash.mjs +63 -34
  37. package/node_modules/typebox/build/system/locale/en_US.mjs +2 -1
  38. package/node_modules/typebox/build/system/memory/assign.d.mts +2 -8
  39. package/node_modules/typebox/build/system/memory/assign.mjs +13 -6
  40. package/node_modules/typebox/build/system/memory/clone.d.mts +4 -5
  41. package/node_modules/typebox/build/system/memory/clone.mjs +8 -96
  42. package/node_modules/typebox/build/system/memory/create.d.mts +1 -5
  43. package/node_modules/typebox/build/system/memory/create.mjs +18 -13
  44. package/node_modules/typebox/build/system/memory/deep.d.mts +2 -0
  45. package/node_modules/typebox/build/system/memory/deep.mjs +108 -0
  46. package/node_modules/typebox/build/system/memory/discard.d.mts +1 -1
  47. package/node_modules/typebox/build/system/memory/discard.mjs +9 -8
  48. package/node_modules/typebox/build/system/memory/finalize.d.mts +4 -0
  49. package/node_modules/typebox/build/system/memory/finalize.mjs +30 -0
  50. package/node_modules/typebox/build/system/memory/keys.d.mts +2 -0
  51. package/node_modules/typebox/build/system/memory/keys.mjs +8 -0
  52. package/node_modules/typebox/build/system/memory/update.d.mts +1 -4
  53. package/node_modules/typebox/build/system/memory/update.mjs +43 -16
  54. package/node_modules/typebox/build/type/engine/call/index.d.mts +1 -0
  55. package/node_modules/typebox/build/type/engine/call/index.mjs +1 -0
  56. package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +2 -24
  57. package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +2 -29
  58. package/node_modules/typebox/build/type/engine/evaluate/index.d.mts +1 -0
  59. package/node_modules/typebox/build/type/engine/evaluate/index.mjs +1 -0
  60. package/node_modules/typebox/build/type/engine/evaluate/narrow.d.mts +5 -1
  61. package/node_modules/typebox/build/type/engine/evaluate/narrow.mjs +6 -1
  62. package/node_modules/typebox/build/type/engine/evaluate/property.d.mts +30 -0
  63. package/node_modules/typebox/build/type/engine/evaluate/property.mjs +29 -0
  64. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.d.mts +1 -3
  65. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.mjs +1 -4
  66. package/node_modules/typebox/build/type/engine/object/from_intersect.d.mts +2 -2
  67. package/node_modules/typebox/build/type/engine/object/from_intersect.mjs +2 -2
  68. package/node_modules/typebox/build/type/engine/object/from_union.d.mts +2 -2
  69. package/node_modules/typebox/build/type/engine/object/from_union.mjs +2 -2
  70. package/node_modules/typebox/build/type/engine/optional/instantiate_add.d.mts +1 -3
  71. package/node_modules/typebox/build/type/engine/optional/instantiate_add.mjs +1 -4
  72. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.d.mts +1 -3
  73. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.mjs +1 -4
  74. package/node_modules/typebox/build/type/engine/this/index.d.mts +1 -0
  75. package/node_modules/typebox/build/type/engine/this/index.mjs +1 -0
  76. package/node_modules/typebox/build/value/clone/clone.d.mts +4 -3
  77. package/node_modules/typebox/build/value/clone/clone.mjs +5 -7
  78. package/node_modules/typebox/build/value/repair/from_cyclic.d.mts +2 -0
  79. package/node_modules/typebox/build/value/repair/from_cyclic.mjs +6 -0
  80. package/node_modules/typebox/build/value/shared/union_priority_sort.mjs +25 -14
  81. package/node_modules/typebox/package.json +1 -1
  82. package/node_modules/typebox/readme.md +1 -1
  83. package/package.json +5 -6
  84. package/scripts/inject-helper-terminal.sh +1 -1
  85. package/scripts/inject-helper.sh +3 -7
  86. package/scripts/install-driver.sh +1 -1
  87. package/src/audio-pump.ts +5 -13
  88. package/src/command-output.ts +3 -0
  89. package/src/driver-setup.ts +15 -23
  90. package/src/helper-results.ts +31 -37
  91. package/src/helper-rpc.ts +55 -68
  92. package/src/helper-supervisor.ts +20 -28
  93. package/src/outbound-call.ts +2 -13
  94. package/src/plugin-paths.ts +13 -23
  95. package/src/preflight.ts +10 -33
  96. package/src/runtime-call-control.ts +11 -23
  97. package/src/runtime-call-events.ts +10 -7
  98. package/src/runtime-carrier-process.ts +1 -5
  99. package/src/runtime-helper-results.ts +5 -38
  100. package/src/runtime-state.ts +178 -10
  101. package/src/runtime-status.ts +2 -3
  102. package/src/runtime.ts +5 -7
  103. package/src/setup.ts +58 -69
  104. package/src/talk-consult-controller.ts +1 -19
  105. package/src/talk-driver.ts +31 -25
  106. package/src/talk-events-summary.ts +8 -19
  107. package/node_modules/typebox/build/system/memory/freeze.d.mts +0 -4
  108. package/node_modules/typebox/build/system/memory/freeze.mjs +0 -6
  109. package/src/call-lifecycle.ts +0 -171
  110. package/src/runtime-lifecycle.ts +0 -17
  111. package/src/talk-initial-greeting.ts +0 -42
@@ -6,6 +6,6 @@ repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
6
6
  osascript <<APPLESCRIPT
7
7
  tell application "Terminal"
8
8
  activate
9
- do script "cd ${repo_root//\"/\\\"} && pnpm inject:helper && pnpm inject:helper:phone; echo; echo FaceTime and Phone helper injection finished"
9
+ do script "cd ${repo_root//\"/\\\"} && pnpm inject:helper; echo; echo FaceTime helper injection finished"
10
10
  end tell
11
11
  APPLESCRIPT
@@ -10,7 +10,7 @@ if [[ "${1:-}" == "--app" ]]; then
10
10
  shift 2
11
11
  fi
12
12
  if [[ $# -gt 0 ]]; then
13
- echo "Usage: $0 [--app FaceTime|Phone]" >&2
13
+ echo "Usage: $0 [--app FaceTime]" >&2
14
14
  exit 2
15
15
  fi
16
16
 
@@ -19,12 +19,8 @@ case "${target_app}" in
19
19
  target_bundle="com.apple.FaceTime"
20
20
  target_executable="/System/Applications/FaceTime.app/Contents/MacOS/FaceTime"
21
21
  ;;
22
- Phone)
23
- target_bundle="com.apple.mobilephone"
24
- target_executable="/System/Applications/Phone.app/Contents/MacOS/Phone"
25
- ;;
26
22
  *)
27
- echo "Unsupported helper app: ${target_app}. Use FaceTime or Phone." >&2
23
+ echo "Unsupported helper app: ${target_app}. Use FaceTime." >&2
28
24
  exit 1
29
25
  ;;
30
26
  esac
@@ -58,7 +54,7 @@ if [[ "$sip_debugging" == enabled ]]; then
58
54
  cat >&2 <<'EOF'
59
55
  System Integrity Protection debugging restrictions are enabled.
60
56
 
61
- This helper uses LLDB to load into Apple's protected FaceTime and Phone apps.
57
+ This helper uses LLDB to load into Apple's protected FaceTime app.
62
58
  Apple's SIP runtime protections reject that attach even for root. Disable SIP
63
59
  debugging restrictions from macOS Recovery, reboot, and rerun facetime.setup
64
60
  before injecting:
@@ -46,7 +46,7 @@ case "${1:-}" in
46
46
  "$here/scripts/verify-xcode-trust.sh" \
47
47
  "$here/scripts/commit-driver-transaction.sh" --uninstall
48
48
  /bin/sh "$here/scripts/remove-user-artifacts.sh" "${HOME}" "${TMPDIR:-/tmp}"
49
- printf 'Removed FaceTime audio and helper artifacts. Quit and reopen FaceTime and Phone before re-enabling the plugin.\n'
49
+ printf 'Removed FaceTime audio and helper artifacts. Quit and reopen FaceTime before re-enabling the plugin.\n'
50
50
  exit 0
51
51
  ;;
52
52
  ""|--ensure)
package/src/audio-pump.ts CHANGED
@@ -234,11 +234,10 @@ export function startFaceTimeAudioPump(params: {
234
234
  onInputAudio: (audio: Buffer) => void;
235
235
  onError?: (error: Error) => boolean | void | Promise<boolean | void>;
236
236
  onSuppressionLost?: (error: Error) => void | Promise<void>;
237
- onPlaybackDrained?: (event: { generation: number; playedFrames: number }) => void;
237
+ onPlaybackDrained?: () => void;
238
238
  }): FaceTimeAudioPump {
239
239
  const childEnv = sanitizedAudioChildEnv();
240
240
  const playbackClock = new PlaybackClock();
241
- let playbackGeneration = 1;
242
241
  let drainTimer: NodeJS.Timeout | undefined;
243
242
  let outputProcess: ChildProcess;
244
243
  const captureProcess = spawnAudioProcess(
@@ -270,10 +269,8 @@ export function startFaceTimeAudioPump(params: {
270
269
  });
271
270
  };
272
271
  const cancelDrainTimer = () => {
273
- if (drainTimer) {
274
- clearTimeout(drainTimer);
275
- drainTimer = undefined;
276
- }
272
+ clearTimeout(drainTimer);
273
+ drainTimer = undefined;
277
274
  };
278
275
  const spawnOutput = () => {
279
276
  // Playback stays out of the capture helper: an in-process AVAudioEngine can
@@ -308,7 +305,6 @@ export function startFaceTimeAudioPump(params: {
308
305
  }
309
306
  const previous = outputProcess;
310
307
  outputProcess = spawnOutput();
311
- playbackGeneration += 1;
312
308
  cancelDrainTimer();
313
309
  playbackClock.reset();
314
310
  void terminateProcess(previous, "SIGKILL");
@@ -422,9 +418,8 @@ export function startFaceTimeAudioPump(params: {
422
418
  return;
423
419
  }
424
420
  cancelDrainTimer();
425
- const generation = playbackGeneration;
426
421
  const notifyWhenDrained = () => {
427
- if (stopped || mediaSuspended || generation !== playbackGeneration) {
422
+ if (stopped || mediaSuspended) {
428
423
  return;
429
424
  }
430
425
  const delayMs = Math.ceil(playbackClock.millisecondsUntilDrained());
@@ -435,10 +430,7 @@ export function startFaceTimeAudioPump(params: {
435
430
  }
436
431
  drainTimer = undefined;
437
432
  playbackClock.retireItems();
438
- params.onPlaybackDrained?.({
439
- generation,
440
- playedFrames: Math.floor(playbackClock.playedFrames()),
441
- });
433
+ params.onPlaybackDrained?.();
442
434
  };
443
435
  notifyWhenDrained();
444
436
  },
@@ -0,0 +1,3 @@
1
+ export function firstLine(value: unknown): string | undefined {
2
+ return typeof value === "string" ? value.trim().split(/\r?\n/u)[0] || undefined : undefined;
3
+ }
@@ -35,41 +35,33 @@ export async function inspectFaceTimeDriver(
35
35
  return readDriverStatus(result.stdout);
36
36
  }
37
37
 
38
- export async function installFaceTimeDriver(
39
- params: DriverSetupParams,
40
- ): Promise<{ changed: boolean; status: "current" }> {
41
- const before = await inspectFaceTimeDriver(params);
42
- if (before === "current") {
43
- return { changed: false, status: "current" };
44
- }
38
+ async function runDriverSetup(params: DriverSetupParams, action: "ensure" | "uninstall") {
45
39
  const script = resolve(params.pluginRoot, "scripts", "install-driver.sh");
46
- const result = await params.runCommandWithTimeout(["/bin/sh", script, "--ensure"], {
40
+ const result = await params.runCommandWithTimeout(["/bin/sh", script, `--${action}`], {
47
41
  // The macOS administrator sheet can legitimately remain open while the
48
42
  // operator is away. Runtime shutdown aborts the whole process tree instead.
49
43
  killProcessTree: true,
50
44
  ...(params.signal ? { signal: params.signal } : {}),
51
45
  });
52
46
  if (result.code !== 0) {
47
+ const label = action === "ensure" ? "audio driver installation" : "uninstall";
53
48
  throw new Error(
54
- `FaceTime audio driver installation failed: ${result.stderr || result.stdout || `exit ${result.code}`}`,
49
+ `FaceTime ${label} failed: ${result.stderr || result.stdout || `exit ${result.code}`}`,
55
50
  );
56
51
  }
57
- const after = await inspectFaceTimeDriver(params);
58
- if (after !== "current") {
59
- throw new Error(`FaceTime audio driver did not become current (status: ${after})`);
52
+ }
53
+
54
+ export async function installFaceTimeDriver(
55
+ params: DriverSetupParams,
56
+ ): Promise<{ changed: boolean; status: "current" }> {
57
+ const before = await inspectFaceTimeDriver(params);
58
+ if (before === "current") {
59
+ return { changed: false, status: "current" };
60
60
  }
61
- return { changed: true, status: after };
61
+ await runDriverSetup(params, "ensure");
62
+ return { changed: true, status: "current" };
62
63
  }
63
64
 
64
65
  export async function uninstallFaceTimeDriver(params: DriverSetupParams): Promise<void> {
65
- const script = resolve(params.pluginRoot, "scripts", "install-driver.sh");
66
- const result = await params.runCommandWithTimeout(["/bin/sh", script, "--uninstall"], {
67
- killProcessTree: true,
68
- ...(params.signal ? { signal: params.signal } : {}),
69
- });
70
- if (result.code !== 0) {
71
- throw new Error(
72
- `FaceTime uninstall failed: ${result.stderr || result.stdout || `exit ${result.code}`}`,
73
- );
74
- }
66
+ await runDriverSetup(params, "uninstall");
75
67
  }
@@ -1,18 +1,23 @@
1
- export type HelperActionResult = Record<string, unknown>;
1
+ export const DIAL_BUNDLES = new Set([
2
+ "com.apple.FaceTime",
3
+ "com.apple.FaceTime.FTConversationService",
4
+ ]);
2
5
 
3
- type FaceTimeNativeActionOutcome =
4
- | { status: "answered-muted" }
5
- | { status: "safe-muted" }
6
- | { status: "media-active" }
7
- | { status: "termination-requested" }
8
- | { status: "absent" };
6
+ export type FaceTimeHelperPeer = {
7
+ bundleIdentifier: string;
8
+ processId: number;
9
+ processStartedAtMs: number;
10
+ connectionGeneration: number;
11
+ };
9
12
 
10
- export class FaceTimeHelperActionError extends Error {
11
- constructor(message: string) {
12
- super(message);
13
- this.name = "FaceTimeHelperActionError";
14
- }
15
- }
13
+ export type HelperActionResult = Record<string, unknown> & {
14
+ helperBundleIdentifier?: string;
15
+ helperPeer?: FaceTimeHelperPeer;
16
+ helperResults?: HelperActionResult[];
17
+ helpersContacted?: number;
18
+ topologyGeneration?: number;
19
+ topologyComplete?: boolean;
20
+ };
16
21
 
17
22
  export class FaceTimeHelperAmbiguousError extends Error {
18
23
  constructor(
@@ -32,33 +37,25 @@ export class FaceTimeHelperUnavailableError extends Error {
32
37
  }
33
38
 
34
39
  export function readHelperResults(result: HelperActionResult): HelperActionResult[] {
35
- return Array.isArray(result.helperResults)
36
- ? result.helperResults.filter((entry): entry is HelperActionResult =>
37
- Boolean(entry && typeof entry === "object"),
38
- )
39
- : [result];
40
+ return result.helperResults ?? [result];
40
41
  }
41
42
 
42
43
  function requireCompleteTopology(result: HelperActionResult): HelperActionResult[] {
43
44
  const results = readHelperResults(result);
44
- if (
45
- result.topologyComplete !== true ||
46
- typeof result.helpersContacted !== "number" ||
47
- results.length !== result.helpersContacted
48
- ) {
45
+ if (result.topologyComplete !== true || results.length !== result.helpersContacted) {
49
46
  throw new FaceTimeHelperAmbiguousError("FaceTime helper topology was incomplete", result);
50
47
  }
51
48
  return results;
52
49
  }
53
50
 
54
- export function projectFaceTimeNativeAction(
51
+ export function assertFaceTimeNativeAction(
55
52
  action: "answer" | "safe-mute" | "unmute" | "activate" | "terminate",
56
53
  result: HelperActionResult,
57
- ): FaceTimeNativeActionOutcome {
54
+ ): void {
58
55
  const results = requireCompleteTopology(result);
59
56
  const present = results.filter((entry) => entry.outcome !== "absent");
60
- // FaceTime and Phone can both proxy the same system TUCall. Accept shared
61
- // visibility only when every helper that found the exact call proves the postcondition.
57
+ // FaceTime and its conversation service can both proxy the same system TUCall.
58
+ // Every helper that found the exact call must prove the postcondition.
62
59
  if (present.length === 0) {
63
60
  throw new FaceTimeHelperAmbiguousError(`FaceTime ${action} carrier owner is missing`, result);
64
61
  }
@@ -73,7 +70,7 @@ export function projectFaceTimeNativeAction(
73
70
  (observed.is_sending_audio === true && observed.is_sending_transmission === true)),
74
71
  )
75
72
  ) {
76
- return { status: "media-active" };
73
+ return;
77
74
  }
78
75
  if (
79
76
  (action === "answer" || action === "safe-mute") &&
@@ -86,27 +83,24 @@ export function projectFaceTimeNativeAction(
86
83
  : observed.downlink_muted === true),
87
84
  )
88
85
  ) {
89
- return { status: action === "answer" ? "answered-muted" : "safe-muted" };
86
+ return;
90
87
  }
91
88
  if (
92
89
  action === "terminate" &&
93
90
  present.every((observed) => observed.outcome === "termination-requested")
94
91
  ) {
95
- return { status: "termination-requested" };
92
+ return;
96
93
  }
97
- throw new FaceTimeHelperActionError(`FaceTime ${action} postcondition was not observed`);
94
+ throw new Error(`FaceTime ${action} postcondition was not observed`);
98
95
  }
99
96
 
100
- export function projectCompleteFaceTimeAbsence(result: HelperActionResult): {
101
- status: "absent";
102
- topologyGeneration: number;
103
- } {
97
+ export function projectCompleteFaceTimeAbsence(result: HelperActionResult): number {
104
98
  const results = requireCompleteTopology(result);
105
99
  if (!results.every((entry) => entry.outcome === "absent" && entry.found === false)) {
106
100
  throw new FaceTimeHelperAmbiguousError("FaceTime carrier is still present", result);
107
101
  }
108
- if (typeof result.topologyGeneration !== "number") {
102
+ if (result.topologyGeneration === undefined) {
109
103
  throw new FaceTimeHelperAmbiguousError("FaceTime topology generation is missing", result);
110
104
  }
111
- return { status: "absent", topologyGeneration: result.topologyGeneration };
105
+ return result.topologyGeneration;
112
106
  }
package/src/helper-rpc.ts CHANGED
@@ -1,16 +1,20 @@
1
- import { createHmac, randomUUID, timingSafeEqual } from "node:crypto";
1
+ import { createHmac, randomUUID } from "node:crypto";
2
2
  import net from "node:net";
3
3
  import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
4
4
  import type { RuntimeLogger } from "openclaw/plugin-sdk/plugin-runtime";
5
+ import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
5
6
  import { asRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
6
7
  import {
7
- FaceTimeHelperActionError,
8
+ DIAL_BUNDLES,
8
9
  FaceTimeHelperAmbiguousError,
9
10
  FaceTimeHelperUnavailableError,
11
+ type FaceTimeHelperPeer,
10
12
  type HelperActionResult,
11
13
  } from "./helper-results.js";
12
14
  import type { FaceTimeDialRequest } from "./outbound-call.js";
13
15
 
16
+ export type { FaceTimeHelperPeer } from "./helper-results.js";
17
+
14
18
  type HelperSocketServerParams = {
15
19
  host: string;
16
20
  port: number;
@@ -24,22 +28,11 @@ type HelperSocketServerParams = {
24
28
  onStale?: (bundleIdentifier: string, processId: number) => void;
25
29
  };
26
30
 
27
- export type FaceTimeHelperPeer = {
28
- bundleIdentifier: string;
29
- processId: number;
30
- processStartedAtMs: number;
31
- connectionGeneration: number;
32
- };
33
-
34
- const FACETIME_DIAL_HELPER_BUNDLES = new Set([
35
- "com.apple.FaceTime",
36
- "com.apple.FaceTime.FTConversationService",
37
- ]);
38
- const FACETIME_HELPER_BUNDLES = new Set([
39
- ...FACETIME_DIAL_HELPER_BUNDLES,
40
- "com.apple.mobilephone",
41
- "com.apple.TelephonyUtilities",
42
- ]);
31
+ // An already injected Phone helper reconnects until Phone exits. Admit even an
32
+ // older build so upgrades do not create a reconnect loop; it remains inert.
33
+ const LEGACY_PHONE_BUNDLES = new Set(["com.apple.mobilephone", "com.apple.TelephonyUtilities"]);
34
+ const FACETIME_HELPER_BUNDLES = new Set([...DIAL_BUNDLES, ...LEGACY_PHONE_BUNDLES]);
35
+ const isCallHelper = (bundleIdentifier: string) => DIAL_BUNDLES.has(bundleIdentifier);
43
36
  const MAX_FRAME_BYTES = 64 * 1024;
44
37
  const MAX_CONNECTIONS = 8;
45
38
  const MAX_PENDING_ACTIONS = 32;
@@ -49,16 +42,6 @@ function helperHmac(ipcKey: string, message: string): string {
49
42
  return createHmac("sha256", ipcKey).update(message).digest("hex");
50
43
  }
51
44
 
52
- function secureStringsEqual(first: string, second: string): boolean {
53
- const firstBuffer = Buffer.from(first);
54
- const secondBuffer = Buffer.from(second);
55
- return (
56
- firstBuffer.length > 0 &&
57
- firstBuffer.length === secondBuffer.length &&
58
- timingSafeEqual(firstBuffer, secondBuffer)
59
- );
60
- }
61
-
62
45
  type PendingRpc = {
63
46
  resolve: (result: HelperActionResult) => void;
64
47
  reject: (error: Error) => void;
@@ -79,9 +62,8 @@ type HelperAuthSession = PendingHelperHandshake & {
79
62
  };
80
63
 
81
64
  function hasExactKeys(record: Record<string, unknown>, keys: readonly string[]): boolean {
82
- const actual = Object.keys(record).toSorted();
83
- const expected = [...keys].toSorted();
84
- return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
65
+ const actual = Object.keys(record);
66
+ return actual.length === keys.length && actual.every((key) => keys.includes(key));
85
67
  }
86
68
 
87
69
  export class FaceTimeHelperSocketServer {
@@ -207,11 +189,18 @@ export class FaceTimeHelperSocketServer {
207
189
  }
208
190
 
209
191
  get connectedSockets(): number {
210
- return this.#socketPeers.size;
192
+ return [...this.#socketPeers.values()].filter((peer) => isCallHelper(peer.bundleIdentifier))
193
+ .length;
211
194
  }
212
195
 
213
196
  get connectedHelperBundles(): string[] {
214
- return [...new Set([...this.#socketPeers.values()].map((peer) => peer.bundleIdentifier))];
197
+ return [
198
+ ...new Set(
199
+ [...this.#socketPeers.values()]
200
+ .filter((peer) => isCallHelper(peer.bundleIdentifier))
201
+ .map((peer) => peer.bundleIdentifier),
202
+ ),
203
+ ];
215
204
  }
216
205
 
217
206
  #handleSocket(socket: net.Socket): void {
@@ -255,7 +244,7 @@ export class FaceTimeHelperSocketServer {
255
244
  });
256
245
  socket.on("close", () => {
257
246
  const disconnectedBundle = this.#socketPeers.get(socket)?.bundleIdentifier;
258
- if (disconnectedBundle) {
247
+ if (disconnectedBundle && isCallHelper(disconnectedBundle)) {
259
248
  this.#connectionGeneration += 1;
260
249
  }
261
250
  this.#sockets.delete(socket);
@@ -267,7 +256,7 @@ export class FaceTimeHelperSocketServer {
267
256
  clearTimeout(deadline);
268
257
  this.#authDeadlineTimers.delete(socket);
269
258
  }
270
- if (disconnectedBundle) {
259
+ if (disconnectedBundle && isCallHelper(disconnectedBundle)) {
271
260
  this.params.onDisconnect?.(disconnectedBundle);
272
261
  }
273
262
  });
@@ -314,19 +303,29 @@ export class FaceTimeHelperSocketServer {
314
303
  if (pending) {
315
304
  this.#pending.delete(transactionId);
316
305
  clearTimeout(pending.timeout);
306
+ // Native payloads cannot supply the socket owner's peer or aggregate facts.
307
+ const peer = this.#socketPeers.get(socket);
308
+ const result = Object.assign(payload, {
309
+ helperBundleIdentifier: peer?.bundleIdentifier ?? "unknown",
310
+ helperPeer: peer,
311
+ helperResults: undefined,
312
+ helpersContacted: undefined,
313
+ topologyGeneration: undefined,
314
+ topologyComplete: undefined,
315
+ });
317
316
  if (typeof payload.error === "string" && payload.error) {
318
317
  pending.reject(
319
318
  payload.ambiguous === true
320
- ? new FaceTimeHelperAmbiguousError(payload.error, payload)
321
- : new FaceTimeHelperActionError(payload.error),
319
+ ? new FaceTimeHelperAmbiguousError(payload.error, result)
320
+ : new Error(payload.error),
322
321
  );
323
322
  } else {
324
- pending.resolve(payload);
323
+ pending.resolve(result);
325
324
  }
326
325
  return;
327
326
  }
328
327
  const peer = this.#socketPeers.get(socket);
329
- if (peer) {
328
+ if (peer && isCallHelper(peer.bundleIdentifier)) {
330
329
  void this.params.onMessage(payload, peer);
331
330
  }
332
331
  }
@@ -371,12 +370,12 @@ export class FaceTimeHelperSocketServer {
371
370
  processId <= 0 ||
372
371
  processStartedAtMs <= 0 ||
373
372
  clientNonce.length < 32 ||
374
- !secureStringsEqual(proof, expectedProof)
373
+ !safeEqualSecret(proof, expectedProof)
375
374
  ) {
376
375
  socket.destroy();
377
376
  return;
378
377
  }
379
- if (buildId !== this.params.buildId) {
378
+ if (buildId !== this.params.buildId && isCallHelper(bundleIdentifier)) {
380
379
  this.params.onStale?.(bundleIdentifier, processId);
381
380
  socket.destroy();
382
381
  return;
@@ -410,7 +409,7 @@ export class FaceTimeHelperSocketServer {
410
409
  !hasExactKeys(record, ["event", "connection_epoch", "proof"]) ||
411
410
  record.connection_epoch !== handshake.connectionEpoch ||
412
411
  typeof record.proof !== "string" ||
413
- !secureStringsEqual(
412
+ !safeEqualSecret(
414
413
  record.proof,
415
414
  helperHmac(handshake.connectionKey, `client-finish\n${handshake.connectionEpoch}`),
416
415
  )
@@ -437,14 +436,18 @@ export class FaceTimeHelperSocketServer {
437
436
  bundleIdentifier: session.bundleIdentifier,
438
437
  processId: session.processId,
439
438
  processStartedAtMs: session.processStartedAtMs,
440
- connectionGeneration: ++this.#connectionGeneration,
439
+ connectionGeneration: isCallHelper(session.bundleIdentifier)
440
+ ? ++this.#connectionGeneration
441
+ : this.#connectionGeneration,
441
442
  });
442
443
  const deadline = this.#authDeadlineTimers.get(socket);
443
444
  if (deadline) {
444
445
  clearTimeout(deadline);
445
446
  this.#authDeadlineTimers.delete(socket);
446
447
  }
447
- this.params.onConnect?.(session.bundleIdentifier);
448
+ if (isCallHelper(session.bundleIdentifier)) {
449
+ this.params.onConnect?.(session.bundleIdentifier);
450
+ }
448
451
  }
449
452
 
450
453
  #consumeHelperEnvelope(
@@ -475,7 +478,7 @@ export class FaceTimeHelperSocketServer {
475
478
  session.connectionKey,
476
479
  `message\nhelper-to-server\n${session.connectionEpoch}\n${record.sequence}\n${record.payload_json}`,
477
480
  );
478
- if (!secureStringsEqual(record.auth, expectedAuth)) {
481
+ if (!safeEqualSecret(record.auth, expectedAuth)) {
479
482
  return undefined;
480
483
  }
481
484
  let payload: unknown;
@@ -510,7 +513,7 @@ export class FaceTimeHelperSocketServer {
510
513
  ),
511
514
  });
512
515
  if (Buffer.byteLength(envelope) > MAX_FRAME_BYTES) {
513
- throw new FaceTimeHelperActionError("FaceTime helper message exceeds the frame limit");
516
+ throw new Error("FaceTime helper message exceeds the frame limit");
514
517
  }
515
518
  session.outgoingSequence = sequence;
516
519
  socket.write(`${envelope}\r\n`);
@@ -520,18 +523,14 @@ export class FaceTimeHelperSocketServer {
520
523
  const socket = [...this.#sockets].find(
521
524
  (candidate) =>
522
525
  !candidate.destroyed &&
523
- FACETIME_DIAL_HELPER_BUNDLES.has(this.#socketPeers.get(candidate)?.bundleIdentifier ?? ""),
526
+ DIAL_BUNDLES.has(this.#socketPeers.get(candidate)?.bundleIdentifier ?? ""),
524
527
  );
525
528
  if (!socket) {
526
529
  throw new FaceTimeHelperUnavailableError(
527
530
  "Authenticated FaceTime dialing helper is not connected to the facetime event socket",
528
531
  );
529
532
  }
530
- return {
531
- ...(await this.#sendActionOnSocket(socket, action, data)),
532
- helperBundleIdentifier: this.#socketPeers.get(socket)?.bundleIdentifier ?? "unknown",
533
- helperPeer: this.#socketPeers.get(socket),
534
- };
533
+ return await this.#sendActionOnSocket(socket, action, data);
535
534
  }
536
535
 
537
536
  async #sendActionToAll(
@@ -543,40 +542,31 @@ export class FaceTimeHelperSocketServer {
543
542
  const sockets = [...this.#sockets].filter(
544
543
  (candidate) =>
545
544
  !candidate.destroyed &&
546
- FACETIME_HELPER_BUNDLES.has(this.#socketPeers.get(candidate)?.bundleIdentifier ?? ""),
545
+ isCallHelper(this.#socketPeers.get(candidate)?.bundleIdentifier ?? ""),
547
546
  );
548
547
  if (sockets.length === 0) {
549
548
  throw new FaceTimeHelperUnavailableError(
550
549
  "FaceTime helper is not connected to the facetime event socket",
551
550
  );
552
551
  }
553
- const peers = sockets.map((socket) => this.#socketPeers.get(socket));
554
552
  const results = await Promise.allSettled(
555
553
  sockets.map((socket) => this.#sendActionOnSocket(socket, action, data, timeoutMs)),
556
554
  );
557
- const fulfilled = results.flatMap((result, index) =>
558
- result.status === "fulfilled" && sockets[index]
559
- ? [
560
- {
561
- ...result.value,
562
- helperBundleIdentifier: peers[index]?.bundleIdentifier ?? "unknown",
563
- helperPeer: peers[index],
564
- },
565
- ]
566
- : [],
555
+ const fulfilled = results.flatMap((result) =>
556
+ result.status === "fulfilled" ? [result.value] : [],
567
557
  );
568
558
  if (fulfilled.length > 0) {
569
559
  const fulfilledProcessIds = new Set(
570
560
  fulfilled.flatMap(({ helperPeer }) => (helperPeer ? [helperPeer.processId] : [])),
571
561
  );
572
562
  return {
563
+ ...fulfilled[fulfilled.length - 1],
573
564
  helpersContacted: sockets.length,
574
565
  topologyGeneration: this.#connectionGeneration,
575
566
  topologyComplete:
576
567
  fulfilled.length === sockets.length &&
577
568
  requiredPeerProcessIds.every((processId) => fulfilledProcessIds.has(processId)),
578
569
  helperResults: fulfilled,
579
- ...fulfilled[fulfilled.length - 1],
580
570
  };
581
571
  }
582
572
  const firstRejected = results.find(
@@ -597,9 +587,6 @@ export class FaceTimeHelperSocketServer {
597
587
  throw new FaceTimeHelperUnavailableError("FaceTime helper action queue is full");
598
588
  }
599
589
  const transactionId = randomUUID();
600
- if (!this.#socketAuthSessions.has(socket)) {
601
- throw new FaceTimeHelperUnavailableError("FaceTime helper socket is not authenticated");
602
- }
603
590
  return await new Promise<HelperActionResult>((resolve, reject) => {
604
591
  const timeout = setTimeout(() => {
605
592
  this.#pending.delete(transactionId);
@@ -3,8 +3,9 @@ import { resolve } from "node:path";
3
3
  import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
4
4
  import type { PluginRuntime, RuntimeLogger } from "openclaw/plugin-sdk/plugin-runtime";
5
5
  import { sleepWithAbort } from "openclaw/plugin-sdk/runtime-env";
6
+ import { DIAL_BUNDLES } from "./helper-results.js";
6
7
 
7
- type FaceTimeHelperTarget = "FaceTime" | "Phone";
8
+ type FaceTimeHelperTarget = "FaceTime";
8
9
 
9
10
  type HelperSupervisorTargetState = {
10
11
  target: FaceTimeHelperTarget;
@@ -27,20 +28,12 @@ type HelperSupervisorParams = {
27
28
  connectedBundles: () => string[];
28
29
  };
29
30
 
30
- const TARGET_BUNDLES: Record<FaceTimeHelperTarget, ReadonlySet<string>> = {
31
- FaceTime: new Set(["com.apple.FaceTime", "com.apple.FaceTime.FTConversationService"]),
32
- Phone: new Set(["com.apple.mobilephone", "com.apple.TelephonyUtilities"]),
33
- };
34
- const TARGET_APP_PATHS: Record<FaceTimeHelperTarget, string> = {
35
- FaceTime: "/System/Applications/FaceTime.app",
36
- Phone: "/System/Applications/Phone.app",
37
- };
38
- const FACETIME_HELPER_TARGETS = ["FaceTime", "Phone"] as const;
31
+ const FACETIME_HELPER_TARGETS = ["FaceTime"] as const;
39
32
 
40
33
  const RETRY_DELAYS_MS = [1_000, 2_000, 5_000, 10_000, 30_000, 60_000] as const;
41
34
 
42
35
  function targetForBundle(bundleIdentifier: string): FaceTimeHelperTarget | undefined {
43
- return FACETIME_HELPER_TARGETS.find((target) => TARGET_BUNDLES[target].has(bundleIdentifier));
36
+ return DIAL_BUNDLES.has(bundleIdentifier) ? "FaceTime" : undefined;
44
37
  }
45
38
 
46
39
  export class FaceTimeHelperSupervisor {
@@ -52,20 +45,20 @@ export class FaceTimeHelperSupervisor {
52
45
 
53
46
  constructor(private readonly params: HelperSupervisorParams) {
54
47
  this.#states = new Map(
55
- FACETIME_HELPER_TARGETS.filter((target) => existsSync(TARGET_APP_PATHS[target])).map(
56
- (target) => [
48
+ FACETIME_HELPER_TARGETS.filter((target) =>
49
+ existsSync(`/System/Applications/${target}.app`),
50
+ ).map((target) => [
51
+ target,
52
+ {
57
53
  target,
58
- {
59
- target,
60
- connected: false,
61
- attempts: 0,
62
- injecting: false,
63
- queued: false,
64
- retryScheduled: false,
65
- stale: false,
66
- },
67
- ],
68
- ),
54
+ connected: false,
55
+ attempts: 0,
56
+ injecting: false,
57
+ queued: false,
58
+ retryScheduled: false,
59
+ stale: false,
60
+ },
61
+ ]),
69
62
  );
70
63
  }
71
64
 
@@ -155,10 +148,9 @@ export class FaceTimeHelperSupervisor {
155
148
  #refreshConnections(): void {
156
149
  const bundles = new Set(this.params.connectedBundles());
157
150
  for (const target of FACETIME_HELPER_TARGETS) {
158
- const acceptedBundles = TARGET_BUNDLES[target];
159
151
  const state = this.#states.get(target);
160
152
  if (state) {
161
- state.connected = [...acceptedBundles].some((bundle) => bundles.has(bundle));
153
+ state.connected = [...DIAL_BUNDLES].some((bundle) => bundles.has(bundle));
162
154
  }
163
155
  }
164
156
  }
@@ -233,8 +225,8 @@ export class FaceTimeHelperSupervisor {
233
225
  }
234
226
 
235
227
  async #waitForAuthenticatedConnection(target: FaceTimeHelperTarget): Promise<void> {
236
- const deadline = Date.now() + 10_000;
237
- while (this.#started && Date.now() < deadline) {
228
+ const deadline = performance.now() + 10_000;
229
+ while (this.#started && performance.now() < deadline) {
238
230
  this.#refreshConnections();
239
231
  const state = this.#states.get(target);
240
232
  if (!state || state.connected || state.stale) {