@openclaw/facetime 2026.10.10 → 2026.11.5-beta.1

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-C3uKLO8_.mjs → setup-ByISvnBj.mjs} +51 -99
  2. package/dist/.source-module-urls/38481bccca5fbb406e50ac928748f9f04f5a6cf5623980901b3cebc6ee82dfb6.json +1 -1
  3. package/dist/index.js +9 -21
  4. package/dist/runtime-api.js +225 -337
  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
@@ -1,15 +1,16 @@
1
- import { l as resolveFaceTimeConfig, n as ensureCaptureBinary, r as ensureHelperArtifacts, s as installFaceTimeDriver, t as runFaceTimeSetup, u as validateFaceTimeConfig } from "./.setup/setup-C3uKLO8_.mjs";
1
+ import { c as installFaceTimeDriver, d as validateFaceTimeConfig, i as ensureHelperArtifacts, n as firstLine, r as ensureCaptureBinary, t as runFaceTimeSetup, u as resolveFaceTimeConfig } from "./.setup/setup-ByISvnBj.mjs";
2
2
  import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
3
3
  import { REALTIME_VOICE_AGENT_CONSULT_TOOL_NAME, REALTIME_VOICE_AUDIO_FORMAT_PCM16_24KHZ, buildRealtimeVoiceAgentCancelProviderResult, buildRealtimeVoiceAgentConsultPolicyInstructions, buildRealtimeVoiceAgentConsultWorkingResponse, consultRealtimeVoiceAgent, createRealtimeVoiceBridgeSession, createTalkSessionController, getRealtimeVoiceProvider, recordRealtimeVoiceTranscript, recordTalkObservabilityEvent, resolveConfiguredRealtimeVoiceProviderAsync, resolveRealtimeVoiceAgentConsultTools, resolveRealtimeVoiceAgentConsultToolsAllow } from "openclaw/plugin-sdk/realtime-voice";
4
4
  import { asBoolean, asFiniteNumber, asRecord, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
5
5
  import { resolve } from "node:path";
6
6
  import { constants, existsSync } from "node:fs";
7
7
  import { access } from "node:fs/promises";
8
- import { createHmac, randomUUID, timingSafeEqual } from "node:crypto";
8
+ import { createHmac, randomUUID } from "node:crypto";
9
9
  import { sleep, sleepWithAbort } from "openclaw/plugin-sdk/runtime-env";
10
- import { createDeferred } from "openclaw/plugin-sdk/extension-shared";
11
10
  import net from "node:net";
11
+ import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
12
12
  import { spawn } from "node:child_process";
13
+ import { createDeferred } from "openclaw/plugin-sdk/extension-shared";
13
14
  import { resolveDefaultAgentId } from "openclaw/plugin-sdk/agent-runtime";
14
15
  import { parseAgentSessionKey, resolveAgentIdFromSessionKey } from "openclaw/plugin-sdk/routing";
15
16
  import { resolveConfiguredSecretInputString } from "openclaw/plugin-sdk/secret-input-runtime";
@@ -157,121 +158,6 @@ function isEndedCall(event) {
157
158
  function isUnknownCallStatus(event) {
158
159
  return !isIncomingRingingCall(event) && !isOutgoingRingingCall(event) && !isActiveCall(event) && !isEndedCall(event);
159
160
  }
160
- // extensions/facetime/src/call-lifecycle.ts
161
- function normalizeCallIdentity(value) {
162
- return value.trim().toLowerCase();
163
- }
164
- var FaceTimeCallInstance = class {
165
- #carrierClosure;
166
- #commandTail;
167
- constructor(canonicalId, phase) {
168
- this.lifecycleAbort = new AbortController();
169
- this.aliases = /* @__PURE__ */ new Set();
170
- this.generation = 1;
171
- this.modelMediaMode = "starting";
172
- this.#carrierClosure = createDeferred();
173
- this.carrierClosure = this.#carrierClosure.promise;
174
- this.#commandTail = Promise.resolve();
175
- this.phase = phase;
176
- this.carrierMode = phase === "ringing" ? "ringing" : "muted";
177
- this.aliases.add(normalizeCallIdentity(canonicalId));
178
- }
179
- captureGeneration() {
180
- return this.generation;
181
- }
182
- assertCurrent(generation, allowClosing = false) {
183
- const phaseAllowed = allowClosing ? this.phase !== "closed" && this.carrierMode !== "closed" : this.phase !== "closing" && this.phase !== "closed";
184
- if (generation !== this.generation || !phaseAllowed || !allowClosing && this.lifecycleAbort.signal.aborted) throw new Error("FaceTime call lifecycle changed during carrier command");
185
- }
186
- async runCarrierCommand(params) {
187
- const previous = this.#commandTail;
188
- const { promise, resolve: release } = createDeferred();
189
- this.#commandTail = promise;
190
- await previous;
191
- try {
192
- this.assertCurrent(params.generation, params.allowClosing);
193
- const result = await params.action();
194
- this.assertCurrent(params.generation, params.allowClosing);
195
- return result;
196
- } finally {
197
- release();
198
- }
199
- }
200
- beginAnswering() {
201
- if (this.phase !== "ringing") throw new Error(`cannot answer FaceTime call in ${this.phase} phase`);
202
- this.phase = "answering";
203
- this.carrierMode = "muted";
204
- return this.generation;
205
- }
206
- markCarrierActive(generation) {
207
- this.assertCurrent(generation);
208
- this.phase = "active";
209
- this.carrierMode = "active";
210
- }
211
- markModelReady(generation) {
212
- this.assertCurrent(generation);
213
- this.modelMediaMode = "ready";
214
- }
215
- markModelActive(generation) {
216
- this.assertCurrent(generation);
217
- this.modelMediaMode = "active";
218
- }
219
- suspendModelMedia() {
220
- if (this.modelMediaMode !== "closed") this.modelMediaMode = "suspended";
221
- }
222
- beginClosing() {
223
- if (this.phase === "closed") return this.generation;
224
- if (this.phase !== "closing") {
225
- this.generation += 1;
226
- this.phase = "closing";
227
- this.carrierMode = "closing";
228
- this.suspendModelMedia();
229
- this.lifecycleAbort.abort(/* @__PURE__ */ new Error("FaceTime call is closing"));
230
- }
231
- return this.generation;
232
- }
233
- markCarrierClosed() {
234
- this.beginClosing();
235
- this.carrierMode = "closed";
236
- this.#carrierClosure.resolve(void 0);
237
- }
238
- markClosed() {
239
- this.phase = "closed";
240
- this.carrierMode = "closed";
241
- this.modelMediaMode = "closed";
242
- }
243
- };
244
- var FaceTimeCallRegistry = class {
245
- #active;
246
- get active() {
247
- return this.#active;
248
- }
249
- get size() {
250
- return this.#active && this.#active.phase !== "closed" ? 1 : 0;
251
- }
252
- values() {
253
- return (this.#active && this.#active.phase !== "closed" ? [this.#active] : [])[Symbol.iterator]();
254
- }
255
- get(identity) {
256
- return this.#active?.aliases.has(normalizeCallIdentity(identity)) ? this.#active : void 0;
257
- }
258
- has(identity) {
259
- return this.get(identity) !== void 0;
260
- }
261
- create(call) {
262
- if (this.#active && this.#active.phase !== "closed") throw new Error("another FaceTime call lifecycle is already active");
263
- this.#active = call;
264
- }
265
- retainAlias(call, identity) {
266
- if (this.#active !== call || call.phase === "closed") throw new Error("cannot retain an alias for an inactive FaceTime call");
267
- call.aliases.add(normalizeCallIdentity(identity));
268
- }
269
- close(call) {
270
- if (this.#active !== call) return;
271
- call.markClosed();
272
- this.#active = void 0;
273
- }
274
- };
275
161
  // extensions/facetime/helper-endpoint.json
276
162
  var host = "127.0.0.1";
277
163
  var basePort = 45670;
@@ -286,12 +172,7 @@ function resolveFaceTimeHelperEndpoint() {
286
172
  };
287
173
  }
288
174
  // extensions/facetime/src/helper-results.ts
289
- var FaceTimeHelperActionError = class extends Error {
290
- constructor(message) {
291
- super(message);
292
- this.name = "FaceTimeHelperActionError";
293
- }
294
- };
175
+ const DIAL_BUNDLES = /* @__PURE__ */ new Set(["com.apple.FaceTime", "com.apple.FaceTime.FTConversationService"]);
295
176
  var FaceTimeHelperAmbiguousError = class extends Error {
296
177
  constructor(message, result = {}) {
297
178
  super(message);
@@ -306,36 +187,30 @@ var FaceTimeHelperUnavailableError = class extends Error {
306
187
  }
307
188
  };
308
189
  function readHelperResults(result) {
309
- return Array.isArray(result.helperResults) ? result.helperResults.filter((entry) => Boolean(entry && typeof entry === "object")) : [result];
190
+ return result.helperResults ?? [result];
310
191
  }
311
192
  function requireCompleteTopology(result) {
312
193
  const results = readHelperResults(result);
313
- if (result.topologyComplete !== true || typeof result.helpersContacted !== "number" || results.length !== result.helpersContacted) throw new FaceTimeHelperAmbiguousError("FaceTime helper topology was incomplete", result);
194
+ if (result.topologyComplete !== true || results.length !== result.helpersContacted) throw new FaceTimeHelperAmbiguousError("FaceTime helper topology was incomplete", result);
314
195
  return results;
315
196
  }
316
- function projectFaceTimeNativeAction(action, result) {
197
+ function assertFaceTimeNativeAction(action, result) {
317
198
  const present = requireCompleteTopology(result).filter((entry) => entry.outcome !== "absent");
318
199
  if (present.length === 0) throw new FaceTimeHelperAmbiguousError(`FaceTime ${action} carrier owner is missing`, result);
319
- if ((action === "unmute" || action === "activate") && present.every((observed) => observed.muted === false && observed.is_uplink_muted === false && typeof observed.conversation_audio_error !== "string" && (action === "unmute" || observed.is_sending_audio === true && observed.is_sending_transmission === true))) return { status: "media-active" };
320
- if ((action === "answer" || action === "safe-mute") && present.every((observed) => observed.muted === true && observed.is_uplink_muted === true && (action === "answer" ? observed.outcome === "answered-muted" : observed.downlink_muted === true))) return { status: action === "answer" ? "answered-muted" : "safe-muted" };
321
- if (action === "terminate" && present.every((observed) => observed.outcome === "termination-requested")) return { status: "termination-requested" };
322
- throw new FaceTimeHelperActionError(`FaceTime ${action} postcondition was not observed`);
200
+ if ((action === "unmute" || action === "activate") && present.every((observed) => observed.muted === false && observed.is_uplink_muted === false && typeof observed.conversation_audio_error !== "string" && (action === "unmute" || observed.is_sending_audio === true && observed.is_sending_transmission === true))) return;
201
+ if ((action === "answer" || action === "safe-mute") && present.every((observed) => observed.muted === true && observed.is_uplink_muted === true && (action === "answer" ? observed.outcome === "answered-muted" : observed.downlink_muted === true))) return;
202
+ if (action === "terminate" && present.every((observed) => observed.outcome === "termination-requested")) return;
203
+ throw new Error(`FaceTime ${action} postcondition was not observed`);
323
204
  }
324
205
  function projectCompleteFaceTimeAbsence(result) {
325
206
  if (!requireCompleteTopology(result).every((entry) => entry.outcome === "absent" && entry.found === false)) throw new FaceTimeHelperAmbiguousError("FaceTime carrier is still present", result);
326
- if (typeof result.topologyGeneration !== "number") throw new FaceTimeHelperAmbiguousError("FaceTime topology generation is missing", result);
327
- return {
328
- status: "absent",
329
- topologyGeneration: result.topologyGeneration
330
- };
207
+ if (result.topologyGeneration === void 0) throw new FaceTimeHelperAmbiguousError("FaceTime topology generation is missing", result);
208
+ return result.topologyGeneration;
331
209
  }
332
210
  // extensions/facetime/src/helper-rpc.ts
333
- const FACETIME_DIAL_HELPER_BUNDLES = /* @__PURE__ */ new Set(["com.apple.FaceTime", "com.apple.FaceTime.FTConversationService"]);
334
- const FACETIME_HELPER_BUNDLES = /* @__PURE__ */ new Set([
335
- ...FACETIME_DIAL_HELPER_BUNDLES,
336
- "com.apple.mobilephone",
337
- "com.apple.TelephonyUtilities"
338
- ]);
211
+ const LEGACY_PHONE_BUNDLES = /* @__PURE__ */ new Set(["com.apple.mobilephone", "com.apple.TelephonyUtilities"]);
212
+ const FACETIME_HELPER_BUNDLES = /* @__PURE__ */ new Set([...DIAL_BUNDLES, ...LEGACY_PHONE_BUNDLES]);
213
+ const isCallHelper = (bundleIdentifier) => DIAL_BUNDLES.has(bundleIdentifier);
339
214
  const MAX_FRAME_BYTES = 65536;
340
215
  const MAX_CONNECTIONS = 8;
341
216
  const MAX_PENDING_ACTIONS = 32;
@@ -343,15 +218,9 @@ const AUTH_DEADLINE_MS = 3e3;
343
218
  function helperHmac(ipcKey, message) {
344
219
  return createHmac("sha256", ipcKey).update(message).digest("hex");
345
220
  }
346
- function secureStringsEqual(first, second) {
347
- const firstBuffer = Buffer.from(first);
348
- const secondBuffer = Buffer.from(second);
349
- return firstBuffer.length > 0 && firstBuffer.length === secondBuffer.length && timingSafeEqual(firstBuffer, secondBuffer);
350
- }
351
221
  function hasExactKeys(record, keys) {
352
- const actual = Object.keys(record).toSorted();
353
- const expected = [...keys].toSorted();
354
- return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
222
+ const actual = Object.keys(record);
223
+ return actual.length === keys.length && actual.every((key) => keys.includes(key));
355
224
  }
356
225
  var FaceTimeHelperSocketServer = class {
357
226
  #server;
@@ -442,10 +311,10 @@ var FaceTimeHelperSocketServer = class {
442
311
  return await this.#sendActionToAll("inspect-call", { callUUIDs }, 750, requiredPeerProcessIds);
443
312
  }
444
313
  get connectedSockets() {
445
- return this.#socketPeers.size;
314
+ return [...this.#socketPeers.values()].filter((peer) => isCallHelper(peer.bundleIdentifier)).length;
446
315
  }
447
316
  get connectedHelperBundles() {
448
- return [...new Set([...this.#socketPeers.values()].map((peer) => peer.bundleIdentifier))];
317
+ return [...new Set([...this.#socketPeers.values()].filter((peer) => isCallHelper(peer.bundleIdentifier)).map((peer) => peer.bundleIdentifier))];
449
318
  }
450
319
  #handleSocket(socket) {
451
320
  if (this.#sockets.size >= MAX_CONNECTIONS) {
@@ -482,7 +351,7 @@ var FaceTimeHelperSocketServer = class {
482
351
  });
483
352
  socket.on("close", () => {
484
353
  const disconnectedBundle = this.#socketPeers.get(socket)?.bundleIdentifier;
485
- if (disconnectedBundle) this.#connectionGeneration += 1;
354
+ if (disconnectedBundle && isCallHelper(disconnectedBundle)) this.#connectionGeneration += 1;
486
355
  this.#sockets.delete(socket);
487
356
  this.#socketPeers.delete(socket);
488
357
  this.#pendingHandshakes.delete(socket);
@@ -492,7 +361,7 @@ var FaceTimeHelperSocketServer = class {
492
361
  clearTimeout(deadline);
493
362
  this.#authDeadlineTimers.delete(socket);
494
363
  }
495
- if (disconnectedBundle) this.params.onDisconnect?.(disconnectedBundle);
364
+ if (disconnectedBundle && isCallHelper(disconnectedBundle)) this.params.onDisconnect?.(disconnectedBundle);
496
365
  });
497
366
  }
498
367
  #handleLine(socket, line) {
@@ -532,12 +401,21 @@ var FaceTimeHelperSocketServer = class {
532
401
  if (pending) {
533
402
  this.#pending.delete(transactionId);
534
403
  clearTimeout(pending.timeout);
535
- if (typeof payload.error === "string" && payload.error) pending.reject(payload.ambiguous === true ? new FaceTimeHelperAmbiguousError(payload.error, payload) : new FaceTimeHelperActionError(payload.error));
536
- else pending.resolve(payload);
404
+ const peer = this.#socketPeers.get(socket);
405
+ const result = Object.assign(payload, {
406
+ helperBundleIdentifier: peer?.bundleIdentifier ?? "unknown",
407
+ helperPeer: peer,
408
+ helperResults: void 0,
409
+ helpersContacted: void 0,
410
+ topologyGeneration: void 0,
411
+ topologyComplete: void 0
412
+ });
413
+ if (typeof payload.error === "string" && payload.error) pending.reject(payload.ambiguous === true ? new FaceTimeHelperAmbiguousError(payload.error, result) : new Error(payload.error));
414
+ else pending.resolve(result);
537
415
  return;
538
416
  }
539
417
  const peer = this.#socketPeers.get(socket);
540
- if (peer) this.params.onMessage(payload, peer);
418
+ if (peer && isCallHelper(peer.bundleIdentifier)) this.params.onMessage(payload, peer);
541
419
  }
542
420
  #handleClientHello(socket, record) {
543
421
  if (this.#pendingHandshakes.has(socket) || this.#socketAuthSessions.has(socket) || !hasExactKeys(record, [
@@ -559,11 +437,11 @@ var FaceTimeHelperSocketServer = class {
559
437
  const clientNonce = typeof record.client_nonce === "string" ? record.client_nonce : "";
560
438
  const proof = typeof record.proof === "string" ? record.proof : "";
561
439
  const expectedProof = helperHmac(this.params.ipcKey, `client-hello\n${bundleIdentifier}\n${buildId}\n${processId}\n${processStartedAtMs}\n${clientNonce}`);
562
- if (!FACETIME_HELPER_BUNDLES.has(bundleIdentifier) || processId <= 0 || processStartedAtMs <= 0 || clientNonce.length < 32 || !secureStringsEqual(proof, expectedProof)) {
440
+ if (!FACETIME_HELPER_BUNDLES.has(bundleIdentifier) || processId <= 0 || processStartedAtMs <= 0 || clientNonce.length < 32 || !safeEqualSecret(proof, expectedProof)) {
563
441
  socket.destroy();
564
442
  return;
565
443
  }
566
- if (buildId !== this.params.buildId) {
444
+ if (buildId !== this.params.buildId && isCallHelper(bundleIdentifier)) {
567
445
  this.params.onStale?.(bundleIdentifier, processId);
568
446
  socket.destroy();
569
447
  return;
@@ -593,7 +471,7 @@ var FaceTimeHelperSocketServer = class {
593
471
  "event",
594
472
  "connection_epoch",
595
473
  "proof"
596
- ]) || record.connection_epoch !== handshake.connectionEpoch || typeof record.proof !== "string" || !secureStringsEqual(record.proof, helperHmac(handshake.connectionKey, `client-finish\n${handshake.connectionEpoch}`))) {
474
+ ]) || record.connection_epoch !== handshake.connectionEpoch || typeof record.proof !== "string" || !safeEqualSecret(record.proof, helperHmac(handshake.connectionKey, `client-finish\n${handshake.connectionEpoch}`))) {
597
475
  socket.destroy();
598
476
  return;
599
477
  }
@@ -615,14 +493,14 @@ var FaceTimeHelperSocketServer = class {
615
493
  bundleIdentifier: session.bundleIdentifier,
616
494
  processId: session.processId,
617
495
  processStartedAtMs: session.processStartedAtMs,
618
- connectionGeneration: ++this.#connectionGeneration
496
+ connectionGeneration: isCallHelper(session.bundleIdentifier) ? ++this.#connectionGeneration : this.#connectionGeneration
619
497
  });
620
498
  const deadline = this.#authDeadlineTimers.get(socket);
621
499
  if (deadline) {
622
500
  clearTimeout(deadline);
623
501
  this.#authDeadlineTimers.delete(socket);
624
502
  }
625
- this.params.onConnect?.(session.bundleIdentifier);
503
+ if (isCallHelper(session.bundleIdentifier)) this.params.onConnect?.(session.bundleIdentifier);
626
504
  }
627
505
  #consumeHelperEnvelope(socket, record) {
628
506
  const session = this.#socketAuthSessions.get(socket);
@@ -634,7 +512,7 @@ var FaceTimeHelperSocketServer = class {
634
512
  "auth"
635
513
  ]) || record.connection_epoch !== session.connectionEpoch || record.direction !== "helper-to-server" || typeof record.sequence !== "number" || !Number.isSafeInteger(record.sequence) || record.sequence !== session.incomingSequence + 1 || typeof record.payload_json !== "string" || typeof record.auth !== "string") return;
636
514
  const expectedAuth = helperHmac(session.connectionKey, `message\nhelper-to-server\n${session.connectionEpoch}\n${record.sequence}\n${record.payload_json}`);
637
- if (!secureStringsEqual(record.auth, expectedAuth)) return;
515
+ if (!safeEqualSecret(record.auth, expectedAuth)) return;
638
516
  let payload;
639
517
  try {
640
518
  payload = JSON.parse(record.payload_json);
@@ -658,37 +536,28 @@ var FaceTimeHelperSocketServer = class {
658
536
  payload_json: payloadJson,
659
537
  auth: helperHmac(session.connectionKey, `message\nserver-to-helper\n${session.connectionEpoch}\n${sequence}\n${payloadJson}`)
660
538
  });
661
- if (Buffer.byteLength(envelope) > MAX_FRAME_BYTES) throw new FaceTimeHelperActionError("FaceTime helper message exceeds the frame limit");
539
+ if (Buffer.byteLength(envelope) > MAX_FRAME_BYTES) throw new Error("FaceTime helper message exceeds the frame limit");
662
540
  session.outgoingSequence = sequence;
663
541
  socket.write(`${envelope}\r\n`);
664
542
  }
665
543
  async #sendAction(action, data) {
666
- const socket = [...this.#sockets].find((candidate) => !candidate.destroyed && FACETIME_DIAL_HELPER_BUNDLES.has(this.#socketPeers.get(candidate)?.bundleIdentifier ?? ""));
544
+ const socket = [...this.#sockets].find((candidate) => !candidate.destroyed && DIAL_BUNDLES.has(this.#socketPeers.get(candidate)?.bundleIdentifier ?? ""));
667
545
  if (!socket) throw new FaceTimeHelperUnavailableError("Authenticated FaceTime dialing helper is not connected to the facetime event socket");
668
- return {
669
- ...await this.#sendActionOnSocket(socket, action, data),
670
- helperBundleIdentifier: this.#socketPeers.get(socket)?.bundleIdentifier ?? "unknown",
671
- helperPeer: this.#socketPeers.get(socket)
672
- };
546
+ return await this.#sendActionOnSocket(socket, action, data);
673
547
  }
674
548
  async #sendActionToAll(action, data, timeoutMs = 5e3, requiredPeerProcessIds = []) {
675
- const sockets = [...this.#sockets].filter((candidate) => !candidate.destroyed && FACETIME_HELPER_BUNDLES.has(this.#socketPeers.get(candidate)?.bundleIdentifier ?? ""));
549
+ const sockets = [...this.#sockets].filter((candidate) => !candidate.destroyed && isCallHelper(this.#socketPeers.get(candidate)?.bundleIdentifier ?? ""));
676
550
  if (sockets.length === 0) throw new FaceTimeHelperUnavailableError("FaceTime helper is not connected to the facetime event socket");
677
- const peers = sockets.map((socket) => this.#socketPeers.get(socket));
678
551
  const results = await Promise.allSettled(sockets.map((socket) => this.#sendActionOnSocket(socket, action, data, timeoutMs)));
679
- const fulfilled = results.flatMap((result, index) => result.status === "fulfilled" && sockets[index] ? [{
680
- ...result.value,
681
- helperBundleIdentifier: peers[index]?.bundleIdentifier ?? "unknown",
682
- helperPeer: peers[index]
683
- }] : []);
552
+ const fulfilled = results.flatMap((result) => result.status === "fulfilled" ? [result.value] : []);
684
553
  if (fulfilled.length > 0) {
685
554
  const fulfilledProcessIds = new Set(fulfilled.flatMap(({ helperPeer }) => helperPeer ? [helperPeer.processId] : []));
686
555
  return {
556
+ ...fulfilled[fulfilled.length - 1],
687
557
  helpersContacted: sockets.length,
688
558
  topologyGeneration: this.#connectionGeneration,
689
559
  topologyComplete: fulfilled.length === sockets.length && requiredPeerProcessIds.every((processId) => fulfilledProcessIds.has(processId)),
690
- helperResults: fulfilled,
691
- ...fulfilled[fulfilled.length - 1]
560
+ helperResults: fulfilled
692
561
  };
693
562
  }
694
563
  const firstRejected = results.find((result) => result.status === "rejected");
@@ -697,7 +566,6 @@ var FaceTimeHelperSocketServer = class {
697
566
  async #sendActionOnSocket(socket, action, data, timeoutMs = 5e3) {
698
567
  if (this.#pending.size >= MAX_PENDING_ACTIONS) throw new FaceTimeHelperUnavailableError("FaceTime helper action queue is full");
699
568
  const transactionId = randomUUID();
700
- if (!this.#socketAuthSessions.has(socket)) throw new FaceTimeHelperUnavailableError("FaceTime helper socket is not authenticated");
701
569
  return await new Promise((resolve, reject) => {
702
570
  const timeout = setTimeout(() => {
703
571
  this.#pending.delete(transactionId);
@@ -723,15 +591,7 @@ var FaceTimeHelperSocketServer = class {
723
591
  }
724
592
  };
725
593
  // extensions/facetime/src/helper-supervisor.ts
726
- const TARGET_BUNDLES = {
727
- FaceTime: /* @__PURE__ */ new Set(["com.apple.FaceTime", "com.apple.FaceTime.FTConversationService"]),
728
- Phone: /* @__PURE__ */ new Set(["com.apple.mobilephone", "com.apple.TelephonyUtilities"])
729
- };
730
- const TARGET_APP_PATHS = {
731
- FaceTime: "/System/Applications/FaceTime.app",
732
- Phone: "/System/Applications/Phone.app"
733
- };
734
- const FACETIME_HELPER_TARGETS = ["FaceTime", "Phone"];
594
+ const FACETIME_HELPER_TARGETS = ["FaceTime"];
735
595
  const RETRY_DELAYS_MS = [
736
596
  1e3,
737
597
  2e3,
@@ -741,7 +601,7 @@ const RETRY_DELAYS_MS = [
741
601
  6e4
742
602
  ];
743
603
  function targetForBundle(bundleIdentifier) {
744
- return FACETIME_HELPER_TARGETS.find((target) => TARGET_BUNDLES[target].has(bundleIdentifier));
604
+ return DIAL_BUNDLES.has(bundleIdentifier) ? "FaceTime" : void 0;
745
605
  }
746
606
  var FaceTimeHelperSupervisor = class {
747
607
  #states;
@@ -751,7 +611,7 @@ var FaceTimeHelperSupervisor = class {
751
611
  #abortController = new AbortController();
752
612
  constructor(params) {
753
613
  this.params = params;
754
- this.#states = new Map(FACETIME_HELPER_TARGETS.filter((target) => existsSync(TARGET_APP_PATHS[target])).map((target) => [target, {
614
+ this.#states = new Map(FACETIME_HELPER_TARGETS.filter((target) => existsSync(`/System/Applications/${target}.app`)).map((target) => [target, {
755
615
  target,
756
616
  connected: false,
757
617
  attempts: 0,
@@ -815,9 +675,8 @@ var FaceTimeHelperSupervisor = class {
815
675
  #refreshConnections() {
816
676
  const bundles = new Set(this.params.connectedBundles());
817
677
  for (const target of FACETIME_HELPER_TARGETS) {
818
- const acceptedBundles = TARGET_BUNDLES[target];
819
678
  const state = this.#states.get(target);
820
- if (state) state.connected = [...acceptedBundles].some((bundle) => bundles.has(bundle));
679
+ if (state) state.connected = [...DIAL_BUNDLES].some((bundle) => bundles.has(bundle));
821
680
  }
822
681
  }
823
682
  #cancelTimer(target) {
@@ -873,8 +732,8 @@ var FaceTimeHelperSupervisor = class {
873
732
  this.#injectionChain = pending.catch(() => void 0);
874
733
  }
875
734
  async #waitForAuthenticatedConnection(target) {
876
- const deadline = Date.now() + 1e4;
877
- while (this.#started && Date.now() < deadline) {
735
+ const deadline = performance.now() + 1e4;
736
+ while (this.#started && performance.now() < deadline) {
878
737
  this.#refreshConnections();
879
738
  const state = this.#states.get(target);
880
739
  if (!state || state.connected || state.stale) return;
@@ -1263,7 +1122,6 @@ function createAudioReadiness() {
1263
1122
  function startFaceTimeAudioPump(params) {
1264
1123
  const childEnv = sanitizedAudioChildEnv();
1265
1124
  const playbackClock = new PlaybackClock();
1266
- let playbackGeneration = 1;
1267
1125
  let drainTimer;
1268
1126
  let outputProcess;
1269
1127
  const captureProcess = spawnAudioProcess({
@@ -1291,10 +1149,8 @@ function startFaceTimeAudioPump(params) {
1291
1149
  });
1292
1150
  };
1293
1151
  const cancelDrainTimer = () => {
1294
- if (drainTimer) {
1295
- clearTimeout(drainTimer);
1296
- drainTimer = void 0;
1297
- }
1152
+ clearTimeout(drainTimer);
1153
+ drainTimer = void 0;
1298
1154
  };
1299
1155
  const spawnOutput = () => {
1300
1156
  const proc = spawnAudioProcess({ kind: "playback" }, childEnv);
@@ -1319,7 +1175,6 @@ function startFaceTimeAudioPump(params) {
1319
1175
  if (stopped || mediaSuspended) return;
1320
1176
  const previous = outputProcess;
1321
1177
  outputProcess = spawnOutput();
1322
- playbackGeneration += 1;
1323
1178
  cancelDrainTimer();
1324
1179
  playbackClock.reset();
1325
1180
  terminateProcess(previous, "SIGKILL");
@@ -1410,9 +1265,8 @@ function startFaceTimeAudioPump(params) {
1410
1265
  return;
1411
1266
  }
1412
1267
  cancelDrainTimer();
1413
- const generation = playbackGeneration;
1414
1268
  const notifyWhenDrained = () => {
1415
- if (stopped || mediaSuspended || generation !== playbackGeneration) return;
1269
+ if (stopped || mediaSuspended) return;
1416
1270
  const delayMs = Math.ceil(playbackClock.millisecondsUntilDrained());
1417
1271
  if (delayMs > 0) {
1418
1272
  drainTimer = setTimeout(notifyWhenDrained, Math.max(1, delayMs));
@@ -1421,10 +1275,7 @@ function startFaceTimeAudioPump(params) {
1421
1275
  }
1422
1276
  drainTimer = void 0;
1423
1277
  playbackClock.retireItems();
1424
- params.onPlaybackDrained?.({
1425
- generation,
1426
- playedFrames: Math.floor(playbackClock.playedFrames())
1427
- });
1278
+ params.onPlaybackDrained?.();
1428
1279
  };
1429
1280
  notifyWhenDrained();
1430
1281
  },
@@ -1554,9 +1405,6 @@ function parseDefaultAudioDevices(raw) {
1554
1405
  }
1555
1406
  };
1556
1407
  }
1557
- function firstLine(value) {
1558
- return typeof value === "string" ? value.trim().split(/\r?\n/u)[0] || void 0 : void 0;
1559
- }
1560
1408
  function pushCheck(checks, check) {
1561
1409
  checks.push({
1562
1410
  required: true,
@@ -1586,27 +1434,6 @@ function findPhysicalOutputProblem(defaults, devices) {
1586
1434
  if (defaults.output.isAggregate) return `system output is aggregate device ${defaults.output.name}`;
1587
1435
  if (devices.some((device) => device.name === defaults.output.name && device.virtual) || /BlackHole|OpenClaw-(?:Feed|Mic)/iu.test(defaults.output.name)) return `system output is virtual device ${defaults.output.name}`;
1588
1436
  }
1589
- async function checkCallApp(params) {
1590
- for (const app of ["FaceTime", "Phone"]) if ((await params.runCommandWithTimeout([
1591
- "/usr/bin/pgrep",
1592
- "-x",
1593
- app
1594
- ], { timeoutMs: 5e3 })).code === 0) {
1595
- pushCheck(params.checks, {
1596
- id: "call-app-running",
1597
- label: "FaceTime or Phone process",
1598
- ok: true,
1599
- message: app
1600
- });
1601
- return;
1602
- }
1603
- pushCheck(params.checks, {
1604
- id: "call-app-running",
1605
- label: "FaceTime or Phone process",
1606
- ok: false,
1607
- message: "open FaceTime for video calls or Phone for FaceTime audio calls"
1608
- });
1609
- }
1610
1437
  async function runFaceTimePreflight(params) {
1611
1438
  const runCommandWithTimeout = params.runtime.system.runCommandWithTimeout;
1612
1439
  const checks = [];
@@ -1627,9 +1454,16 @@ async function runFaceTimePreflight(params) {
1627
1454
  ok: executable.code === 0,
1628
1455
  message: executable.code === 0 ? params.captureBinary : "capture helper is missing; reinstall with brew install openclaw/tap/openclaw-facetime"
1629
1456
  });
1630
- await checkCallApp({
1631
- runCommandWithTimeout,
1632
- checks
1457
+ const result = await runCommandWithTimeout([
1458
+ "/usr/bin/pgrep",
1459
+ "-x",
1460
+ "FaceTime"
1461
+ ], { timeoutMs: 5e3 });
1462
+ pushCheck(checks, {
1463
+ id: "call-app-running",
1464
+ label: "FaceTime process",
1465
+ ok: result.code === 0,
1466
+ message: result.code === 0 ? "FaceTime" : "open FaceTime for audio or video calls"
1633
1467
  });
1634
1468
  const profiler = await runCommandWithTimeout([
1635
1469
  "/usr/sbin/system_profiler",
@@ -1731,7 +1565,7 @@ async function terminateExactCarrierProcesses(params) {
1731
1565
  params.assertCurrent();
1732
1566
  if (params.peers.size === 0) throw new Error("no authenticated carrier process identity is available for safe shutdown");
1733
1567
  for (const peer of params.peers.values()) {
1734
- const expected = peer.bundleIdentifier === "com.apple.FaceTime" ? "FaceTime" : peer.bundleIdentifier === "com.apple.FaceTime.FTConversationService" ? "FTConversationService" : peer.bundleIdentifier === "com.apple.mobilephone" ? "Phone" : peer.bundleIdentifier === "com.apple.TelephonyUtilities" ? "TelephonyUtilities" : "";
1568
+ const expected = peer.bundleIdentifier === "com.apple.FaceTime" ? "FaceTime" : peer.bundleIdentifier === "com.apple.FaceTime.FTConversationService" ? "FTConversationService" : "";
1735
1569
  const inspectExactProcess = async () => {
1736
1570
  const inspected = await params.runtime.system.runCommandWithTimeout([
1737
1571
  "/bin/ps",
@@ -1774,19 +1608,8 @@ async function terminateExactCarrierProcesses(params) {
1774
1608
  }
1775
1609
  }
1776
1610
  // extensions/facetime/src/runtime-helper-results.ts
1777
- const OUTBOUND_DIAL_HELPER_BUNDLES = /* @__PURE__ */ new Set(["com.apple.FaceTime", "com.apple.FaceTime.FTConversationService"]);
1778
1611
  function readHelperPeers(result) {
1779
- const peers = [];
1780
- for (const entry of readHelperResults(result)) {
1781
- const peer = entry.helperPeer;
1782
- if (peer && typeof peer === "object" && "processId" in peer && "bundleIdentifier" in peer && "connectionGeneration" in peer && "processStartedAtMs" in peer && typeof peer.processId === "number" && typeof peer.bundleIdentifier === "string" && typeof peer.connectionGeneration === "number" && typeof peer.processStartedAtMs === "number") peers.push({
1783
- bundleIdentifier: peer.bundleIdentifier,
1784
- processId: peer.processId,
1785
- processStartedAtMs: peer.processStartedAtMs,
1786
- connectionGeneration: peer.connectionGeneration
1787
- });
1788
- }
1789
- return peers;
1612
+ return readHelperResults(result).flatMap((entry) => entry.helperPeer ? [entry.helperPeer] : []);
1790
1613
  }
1791
1614
  function retainHelperResultPeers(call, result) {
1792
1615
  for (const peer of readHelperPeers(result)) call.carrierPeers.set(peer.processId, peer);
@@ -1794,7 +1617,7 @@ function retainHelperResultPeers(call, result) {
1794
1617
  function retainOutboundDialHelperPeers(peers, result) {
1795
1618
  for (const entry of readHelperResults(result)) {
1796
1619
  if (entry.found === false && entry.retained_outbound_dial !== true && entry.cancelled !== true) continue;
1797
- for (const peer of readHelperPeers(entry)) if (OUTBOUND_DIAL_HELPER_BUNDLES.has(peer.bundleIdentifier)) peers.set(peer.processId, peer);
1620
+ for (const peer of readHelperPeers(entry)) if (DIAL_BUNDLES.has(peer.bundleIdentifier)) peers.set(peer.processId, peer);
1798
1621
  }
1799
1622
  }
1800
1623
  function readOutboundCallUUID(result) {
@@ -1804,7 +1627,7 @@ function readOutboundProxyIdentifier(result) {
1804
1627
  return readHelperResults(result).map((entry) => normalizeOptionalString(entry.proxy_identifier)).find((value) => Boolean(value));
1805
1628
  }
1806
1629
  function hasDialHelperConfirmation(results) {
1807
- return results.some((entry) => typeof entry.helperBundleIdentifier === "string" && OUTBOUND_DIAL_HELPER_BUNDLES.has(entry.helperBundleIdentifier));
1630
+ return results.some((entry) => DIAL_BUNDLES.has(entry.helperBundleIdentifier ?? ""));
1808
1631
  }
1809
1632
  function hasDefinitiveDialHelperAbsence(result, requiredPeerProcessIds) {
1810
1633
  const results = readHelperResults(result);
@@ -1836,7 +1659,7 @@ async function reconcilePendingFaceTimeCarrier(params) {
1836
1659
  await params.persist();
1837
1660
  }
1838
1661
  if (reconciledCallUUID || reconciledProxyIdentifier || readHelperResults(result).some((entry) => entry.found === true)) return;
1839
- const topologyGeneration = typeof result.topologyGeneration === "number" ? result.topologyGeneration : void 0;
1662
+ const topologyGeneration = result.topologyGeneration;
1840
1663
  const completeAbsence = hasDefinitiveDialHelperAbsence(result, params.peers.keys());
1841
1664
  if (completeAbsence && topologyGeneration !== void 0 && topologyGeneration === previousAbsentTopology && previousAbsenceCurrent?.()) {
1842
1665
  await params.clear();
@@ -1873,7 +1696,6 @@ function createFaceTimeConsultController(params) {
1873
1696
  };
1874
1697
  const abortConsult = (consult, reason) => {
1875
1698
  consult.abortController.abort(/* @__PURE__ */ new Error(`FaceTime agent consult ${reason}`));
1876
- consult.runRegistration?.controller.abort(/* @__PURE__ */ new Error(`FaceTime agent consult run ${reason}`));
1877
1699
  };
1878
1700
  const abortForClose = () => {
1879
1701
  for (const consult of pending.values()) {
@@ -2085,7 +1907,7 @@ function createFaceTimeConsultController(params) {
2085
1907
  sessionKey: params.consultSessionKey,
2086
1908
  spawnedBy: params.requesterSessionKey,
2087
1909
  senderId: params.senderId,
2088
- senderIsOwner: params.senderIsOwner,
1910
+ senderIsOwner: true,
2089
1911
  contextMode: "fork",
2090
1912
  messageProvider: AGENT_CONSULT_MESSAGE_PROVIDER,
2091
1913
  lane: `facetime:${params.normalizedCallUUID}`,
@@ -2099,21 +1921,7 @@ function createFaceTimeConsultController(params) {
2099
1921
  toolsAllow: resolveRealtimeVoiceAgentConsultToolsAllow(params.config.realtime.toolPolicy),
2100
1922
  extraSystemPrompt: CONSULT_SYSTEM_PROMPT,
2101
1923
  thinkLevel: "off",
2102
- abortSignal: consult.abortController.signal,
2103
- onRunStarted: ({ runId }) => {
2104
- const registration = {
2105
- runId,
2106
- controller: new AbortController()
2107
- };
2108
- consult.runRegistration = registration;
2109
- if (consult.cancelRequested || pending.get(consult.callId) !== consult) registration.controller.abort(/* @__PURE__ */ new Error("FaceTime agent consult was already cancelled"));
2110
- return {
2111
- abortSignal: registration.controller.signal,
2112
- cleanup: () => {
2113
- if (consult.runRegistration === registration) consult.runRegistration = void 0;
2114
- }
2115
- };
2116
- }
1924
+ abortSignal: consult.abortController.signal
2117
1925
  }).then((result) => deliverResult(result), async (error) => {
2118
1926
  if (!ownsConsult(consult) || consult.cancelRequested) return;
2119
1927
  const message = formatErrorMessage(error);
@@ -2126,36 +1934,9 @@ function createFaceTimeConsultController(params) {
2126
1934
  handleToolCall
2127
1935
  };
2128
1936
  }
2129
- // extensions/facetime/src/talk-initial-greeting.ts
1937
+ // extensions/facetime/src/talk-driver.ts
2130
1938
  const FACETIME_INITIAL_GREETING = "Greet the caller briefly, introduce yourself using your configured identity, and ask how you can help.";
2131
1939
  const FACETIME_GREETING_MEDIA_SETTLE_MS = 100;
2132
- function createFaceTimeInitialGreeting(params) {
2133
- let timer;
2134
- let dismissed = false;
2135
- const clear = () => {
2136
- if (timer) {
2137
- clearTimeout(timer);
2138
- timer = void 0;
2139
- }
2140
- };
2141
- return {
2142
- instructions: FACETIME_INITIAL_GREETING,
2143
- schedule() {
2144
- if (dismissed || timer) return;
2145
- timer = setTimeout(() => {
2146
- timer = void 0;
2147
- dismissed = true;
2148
- params.speak(FACETIME_INITIAL_GREETING);
2149
- }, FACETIME_GREETING_MEDIA_SETTLE_MS);
2150
- timer.unref?.();
2151
- },
2152
- cancel() {
2153
- dismissed = true;
2154
- clear();
2155
- }
2156
- };
2157
- }
2158
- // extensions/facetime/src/talk-driver.ts
2159
1940
  async function startFaceTimeTalkDriver(params) {
2160
1941
  if (params.signal?.aborted) throw new Error("FaceTime talk startup aborted");
2161
1942
  const consultAgentId = agentIdFromSessionKey(params.config.realtime.sessionKey, params.fullConfig);
@@ -2185,7 +1966,6 @@ async function startFaceTimeTalkDriver(params) {
2185
1966
  let response;
2186
1967
  const settledResponseIds = /* @__PURE__ */ new Set();
2187
1968
  let suppressNextUnkeyedLegacyTerminal = false;
2188
- const consultRef = {};
2189
1969
  let failurePromise;
2190
1970
  let activated = false;
2191
1971
  let providerReady = false;
@@ -2208,9 +1988,25 @@ async function startFaceTimeTalkDriver(params) {
2208
1988
  startupFailure = error;
2209
1989
  startupFailureDeferred.reject(error);
2210
1990
  };
2211
- const initialGreeting = createFaceTimeInitialGreeting({ speak: (instructions) => {
2212
- if (!stopped && !mediaSuspended && activated && providerReady) bridge?.triggerGreeting(instructions);
2213
- } });
1991
+ let timer;
1992
+ let dismissed = false;
1993
+ const initialGreeting = {
1994
+ instructions: FACETIME_INITIAL_GREETING,
1995
+ schedule() {
1996
+ if (dismissed || timer) return;
1997
+ timer = setTimeout(() => {
1998
+ timer = void 0;
1999
+ dismissed = true;
2000
+ if (!stopped && !mediaSuspended && activated && providerReady) bridge?.triggerGreeting(FACETIME_INITIAL_GREETING);
2001
+ }, FACETIME_GREETING_MEDIA_SETTLE_MS);
2002
+ timer.unref?.();
2003
+ },
2004
+ cancel() {
2005
+ dismissed = true;
2006
+ clearTimeout(timer);
2007
+ timer = void 0;
2008
+ }
2009
+ };
2214
2010
  const reportFailure = (error) => {
2215
2011
  if (failurePromise) return failurePromise;
2216
2012
  failurePromise = Promise.resolve(params.onFailure?.(error)).then((safeToClose) => safeToClose !== false);
@@ -2225,7 +2021,7 @@ async function startFaceTimeTalkDriver(params) {
2225
2021
  mediaSuspensionError ??= /* @__PURE__ */ new Error(`FaceTime model media suspended: ${reason}`);
2226
2022
  mediaSuspendedDeferred.reject(mediaSuspensionError);
2227
2023
  interruptProviderConnect?.();
2228
- consultRef.current?.abortForClose();
2024
+ consultController.abortForClose();
2229
2025
  suspendMediaPromise = (async () => {
2230
2026
  try {
2231
2027
  await bridge?.close();
@@ -2334,7 +2130,7 @@ async function startFaceTimeTalkDriver(params) {
2334
2130
  };
2335
2131
  const resetProviderContinuity = () => {
2336
2132
  modelMediaGeneration += 1;
2337
- consultRef.current?.abortForClose();
2133
+ consultController.abortForClose();
2338
2134
  pump?.clearOutputAudio();
2339
2135
  resetResponsePlayback();
2340
2136
  finishOutputAudio("continuity-reset");
@@ -2350,7 +2146,6 @@ async function startFaceTimeTalkDriver(params) {
2350
2146
  requesterSessionKey,
2351
2147
  normalizedCallUUID,
2352
2148
  senderId: params.senderId,
2353
- senderIsOwner: params.senderIsOwner,
2354
2149
  transcript,
2355
2150
  getBridge: () => bridge,
2356
2151
  getGeneration: () => modelMediaGeneration,
@@ -2362,7 +2157,6 @@ async function startFaceTimeTalkDriver(params) {
2362
2157
  close,
2363
2158
  onHangupRequested: params.onHangupRequested
2364
2159
  });
2365
- consultRef.current = consultController;
2366
2160
  remember({
2367
2161
  type: "session.started",
2368
2162
  payload: { callUUID: params.callUUID }
@@ -2590,7 +2384,6 @@ async function startFaceTimeTalkDriver(params) {
2590
2384
  throw error;
2591
2385
  }
2592
2386
  return {
2593
- callUUID: params.callUUID,
2594
2387
  get recentTalkEvents() {
2595
2388
  return talk.recentEvents;
2596
2389
  },
@@ -2625,7 +2418,7 @@ function createFaceTimeCallControl(params) {
2625
2418
  allowClosing: true,
2626
2419
  action: async () => await request.run(candidate)
2627
2420
  });
2628
- projectFaceTimeNativeAction(request.action, result);
2421
+ assertFaceTimeNativeAction(request.action, result);
2629
2422
  request.call.promoteCarrierCallUUID(candidate);
2630
2423
  return result;
2631
2424
  } catch (error) {
@@ -2653,8 +2446,7 @@ function createFaceTimeCallControl(params) {
2653
2446
  captureBinary: params.captureBinary,
2654
2447
  feedDevice: "OpenClaw-Feed",
2655
2448
  microphoneDevice: "OpenClaw-Mic",
2656
- processInputVerified: false,
2657
- processOutputSuppressed: false
2449
+ processInputVerified: false
2658
2450
  };
2659
2451
  call.lastRoutingError = void 0;
2660
2452
  })();
@@ -2672,26 +2464,23 @@ function createFaceTimeCallControl(params) {
2672
2464
  if (call.lifecycleAbort.signal.aborted) throw new Error("FaceTime call closed during audio routing");
2673
2465
  };
2674
2466
  const enableCallAudio = async (call) => {
2675
- const generation = call.captureGeneration();
2467
+ const generation = call.generation;
2676
2468
  const mutedResult = await call.runCarrierCommand({
2677
2469
  generation,
2678
2470
  action: async () => await params.helper.setMuted(call.carrierCallUUID, false)
2679
2471
  });
2680
2472
  call.lastHelperAction = mutedResult;
2681
2473
  retainHelperResultPeers(call, mutedResult);
2682
- projectFaceTimeNativeAction("unmute", mutedResult);
2474
+ assertFaceTimeNativeAction("unmute", mutedResult);
2683
2475
  const transmissionResult = await call.runCarrierCommand({
2684
2476
  generation,
2685
2477
  action: async () => await params.helper.startTransmission(call.carrierCallUUID)
2686
2478
  });
2687
2479
  call.lastHelperAction = transmissionResult;
2688
2480
  retainHelperResultPeers(call, transmissionResult);
2689
- projectFaceTimeNativeAction("activate", transmissionResult);
2481
+ assertFaceTimeNativeAction("activate", transmissionResult);
2690
2482
  call.markCarrierActive(generation);
2691
- if (call.audioTransport) {
2692
- call.audioTransport.processInputVerified = true;
2693
- call.audioTransport.processOutputSuppressed = call.talk?.processOutputSuppressed() === true;
2694
- }
2483
+ if (call.audioTransport) call.audioTransport.processInputVerified = true;
2695
2484
  };
2696
2485
  const closeCall = async (call, reason) => {
2697
2486
  if (params.calls.active !== call) return;
@@ -2730,7 +2519,7 @@ function createFaceTimeCallControl(params) {
2730
2519
  const readCompleteAbsenceGeneration = (error) => {
2731
2520
  if (!(error instanceof FaceTimeHelperAmbiguousError)) return;
2732
2521
  try {
2733
- return projectCompleteFaceTimeAbsence(error.result).topologyGeneration;
2522
+ return projectCompleteFaceTimeAbsence(error.result);
2734
2523
  } catch {
2735
2524
  return;
2736
2525
  }
@@ -2761,8 +2550,7 @@ function createFaceTimeCallControl(params) {
2761
2550
  });
2762
2551
  const first = projectCompleteFaceTimeAbsence(await inspect());
2763
2552
  await sleepWithAbort(100, void 0, { ref: false });
2764
- const second = projectCompleteFaceTimeAbsence(await inspect());
2765
- return first.topologyGeneration === second.topologyGeneration && params.getHelperTopologyVersion() === topologyVersion;
2553
+ return first === projectCompleteFaceTimeAbsence(await inspect()) && params.getHelperTopologyVersion() === topologyVersion;
2766
2554
  } catch {
2767
2555
  return false;
2768
2556
  }
@@ -2805,7 +2593,7 @@ function createFaceTimeCallControl(params) {
2805
2593
  })()]);
2806
2594
  };
2807
2595
  const terminateCarrierProcesses = async (call) => {
2808
- const generation = call.captureGeneration();
2596
+ const generation = call.generation;
2809
2597
  await terminateExactCarrierProcesses({
2810
2598
  runtime: params.runtime,
2811
2599
  peers: call.carrierPeers,
@@ -2836,7 +2624,6 @@ function createFaceTimeCallControl(params) {
2836
2624
  logger: params.logger,
2837
2625
  callUUID,
2838
2626
  senderId: call.senderId,
2839
- senderIsOwner: call.senderIsOwner,
2840
2627
  captureBinary: params.captureBinary,
2841
2628
  signal: call.lifecycleAbort.signal,
2842
2629
  async onHangupRequested() {
@@ -2856,7 +2643,6 @@ function createFaceTimeCallControl(params) {
2856
2643
  return;
2857
2644
  }
2858
2645
  call.talk = talk;
2859
- if (call.audioTransport) call.audioTransport.processOutputSuppressed = true;
2860
2646
  params.logger.info("[facetime] realtime talk suppression ready");
2861
2647
  })();
2862
2648
  }
@@ -2868,13 +2654,11 @@ function createFaceTimeCallControl(params) {
2868
2654
  }
2869
2655
  };
2870
2656
  const activateCallTalk = async (call) => {
2871
- const generation = call.captureGeneration();
2657
+ const generation = call.generation;
2872
2658
  if (!call.talkActivation) call.talkActivation = (async () => {
2873
2659
  await call.talk?.readyForAudio();
2874
- call.assertCurrent(generation);
2875
2660
  call.markModelReady(generation);
2876
2661
  await enableCallAudio(call);
2877
- call.assertCurrent(generation);
2878
2662
  call.markModelActive(generation);
2879
2663
  call.talk?.activate();
2880
2664
  })();
@@ -2896,13 +2680,26 @@ function createFaceTimeCallControl(params) {
2896
2680
  };
2897
2681
  }
2898
2682
  // extensions/facetime/src/runtime-state.ts
2899
- var ActiveFaceTimeCall = class extends FaceTimeCallInstance {
2683
+ function normalizeCallIdentity(value) {
2684
+ return value.trim().toLowerCase();
2685
+ }
2686
+ var ActiveFaceTimeCall = class {
2687
+ #carrierClosure;
2688
+ #commandTail;
2900
2689
  constructor(params) {
2901
- super(params.callUUID, params.phase);
2690
+ this.lifecycleAbort = new AbortController();
2691
+ this.aliases = /* @__PURE__ */ new Set();
2692
+ this.generation = 1;
2693
+ this.modelMediaMode = "starting";
2694
+ this.#carrierClosure = createDeferred();
2695
+ this.carrierClosure = this.#carrierClosure.promise;
2696
+ this.#commandTail = Promise.resolve();
2902
2697
  this.retiredCarrierCallUUIDs = /* @__PURE__ */ new Set();
2903
2698
  this.carrierPeers = /* @__PURE__ */ new Map();
2904
- this.senderIsOwner = true;
2905
2699
  this.audioReady = false;
2700
+ this.phase = params.phase;
2701
+ this.carrierMode = params.phase === "ringing" ? "ringing" : "muted";
2702
+ this.aliases.add(normalizeCallIdentity(params.callUUID));
2906
2703
  this.callUUID = params.callUUID;
2907
2704
  this.carrierCallUUID = params.callUUID;
2908
2705
  this.carrierCallUUIDs = /* @__PURE__ */ new Set([params.callUUID]);
@@ -2910,6 +2707,67 @@ var ActiveFaceTimeCall = class extends FaceTimeCallInstance {
2910
2707
  this.handle = params.handle;
2911
2708
  if (params.peer) this.carrierPeers.set(params.peer.processId, params.peer);
2912
2709
  }
2710
+ assertCurrent(generation, allowClosing = false) {
2711
+ const phaseAllowed = allowClosing ? this.phase !== "closed" && this.carrierMode !== "closed" : this.phase !== "closing" && this.phase !== "closed";
2712
+ if (generation !== this.generation || !phaseAllowed || !allowClosing && this.lifecycleAbort.signal.aborted) throw new Error("FaceTime call lifecycle changed during carrier command");
2713
+ }
2714
+ async runCarrierCommand(params) {
2715
+ const previous = this.#commandTail;
2716
+ const { promise, resolve: release } = createDeferred();
2717
+ this.#commandTail = promise;
2718
+ await previous;
2719
+ try {
2720
+ this.assertCurrent(params.generation, params.allowClosing);
2721
+ const result = await params.action();
2722
+ this.assertCurrent(params.generation, params.allowClosing);
2723
+ return result;
2724
+ } finally {
2725
+ release();
2726
+ }
2727
+ }
2728
+ beginAnswering() {
2729
+ if (this.phase !== "ringing") throw new Error(`cannot answer FaceTime call in ${this.phase} phase`);
2730
+ this.phase = "answering";
2731
+ this.carrierMode = "muted";
2732
+ return this.generation;
2733
+ }
2734
+ markCarrierActive(generation) {
2735
+ this.assertCurrent(generation);
2736
+ this.phase = "active";
2737
+ this.carrierMode = "active";
2738
+ }
2739
+ markModelReady(generation) {
2740
+ this.assertCurrent(generation);
2741
+ this.modelMediaMode = "ready";
2742
+ }
2743
+ markModelActive(generation) {
2744
+ this.assertCurrent(generation);
2745
+ this.modelMediaMode = "active";
2746
+ }
2747
+ suspendModelMedia() {
2748
+ if (this.modelMediaMode !== "closed") this.modelMediaMode = "suspended";
2749
+ }
2750
+ beginClosing() {
2751
+ if (this.phase === "closed") return this.generation;
2752
+ if (this.phase !== "closing") {
2753
+ this.generation += 1;
2754
+ this.phase = "closing";
2755
+ this.carrierMode = "closing";
2756
+ this.suspendModelMedia();
2757
+ this.lifecycleAbort.abort(/* @__PURE__ */ new Error("FaceTime call is closing"));
2758
+ }
2759
+ return this.generation;
2760
+ }
2761
+ markCarrierClosed() {
2762
+ this.beginClosing();
2763
+ this.carrierMode = "closed";
2764
+ this.#carrierClosure.resolve(void 0);
2765
+ }
2766
+ markClosed() {
2767
+ this.phase = "closed";
2768
+ this.carrierMode = "closed";
2769
+ this.modelMediaMode = "closed";
2770
+ }
2913
2771
  promoteCarrierCallUUID(callUUID) {
2914
2772
  if (callUUID !== this.carrierCallUUID) {
2915
2773
  this.retiredCarrierCallUUIDs.add(this.carrierCallUUID);
@@ -2919,6 +2777,37 @@ var ActiveFaceTimeCall = class extends FaceTimeCallInstance {
2919
2777
  this.carrierCallUUID = callUUID;
2920
2778
  }
2921
2779
  };
2780
+ var FaceTimeCallRegistry = class {
2781
+ #active;
2782
+ get active() {
2783
+ return this.#active;
2784
+ }
2785
+ get size() {
2786
+ return this.#active && this.#active.phase !== "closed" ? 1 : 0;
2787
+ }
2788
+ values() {
2789
+ return (this.#active && this.#active.phase !== "closed" ? [this.#active] : [])[Symbol.iterator]();
2790
+ }
2791
+ get(identity) {
2792
+ return this.#active?.aliases.has(normalizeCallIdentity(identity)) ? this.#active : void 0;
2793
+ }
2794
+ has(identity) {
2795
+ return this.get(identity) !== void 0;
2796
+ }
2797
+ create(call) {
2798
+ if (this.#active && this.#active.phase !== "closed") throw new Error("another FaceTime call lifecycle is already active");
2799
+ this.#active = call;
2800
+ }
2801
+ retainAlias(call, identity) {
2802
+ if (this.#active !== call || call.phase === "closed") throw new Error("cannot retain an alias for an inactive FaceTime call");
2803
+ call.aliases.add(normalizeCallIdentity(identity));
2804
+ }
2805
+ close(call) {
2806
+ if (this.#active !== call) return;
2807
+ call.markClosed();
2808
+ this.#active = void 0;
2809
+ }
2810
+ };
2922
2811
  function updateCallStatus(call, event) {
2923
2812
  call.callStatus = event.data.call_status;
2924
2813
  call.isSendingAudio = event.data.is_sending_audio ?? call.isSendingAudio;
@@ -3017,7 +2906,7 @@ function createFaceTimeCallEventHandler(params) {
3017
2906
  generation,
3018
2907
  action: async () => await params.helper.answerCall(callUUID)
3019
2908
  });
3020
- projectFaceTimeNativeAction("answer", answerResult);
2909
+ assertFaceTimeNativeAction("answer", answerResult);
3021
2910
  retainHelperResultPeers(call, answerResult);
3022
2911
  await params.callControl.activateCallTalk(call);
3023
2912
  params.logger.info("[facetime] answered authorized FaceTime call");
@@ -3123,14 +3012,14 @@ function createFaceTimeCallEventHandler(params) {
3123
3012
  retainPendingDial(ringingCall, pending);
3124
3013
  }
3125
3014
  if (ringingCall) try {
3126
- const generation = ringingCall.captureGeneration();
3015
+ const generation = ringingCall.generation;
3127
3016
  const muteResult = await ringingCall.runCarrierCommand({
3128
3017
  generation,
3129
3018
  action: async () => await params.helper.safetyMute(ringingCall.carrierCallUUID)
3130
3019
  });
3131
3020
  ringingCall.lastHelperAction = muteResult;
3132
3021
  retainHelperResultPeers(ringingCall, muteResult);
3133
- projectFaceTimeNativeAction("safe-mute", muteResult);
3022
+ assertFaceTimeNativeAction("safe-mute", muteResult);
3134
3023
  } catch (error) {
3135
3024
  params.logger.warn(`[facetime] outbound ringing safety mute failed: ${formatErrorMessage(error)}`);
3136
3025
  await params.callControl.attemptCarrierHangup(ringingCall, "outbound-ringing-safety-mute-failed");
@@ -3188,13 +3077,12 @@ function createFaceTimeCallEventHandler(params) {
3188
3077
  // extensions/facetime/src/talk-events-summary.ts
3189
3078
  function summarizeRecentTalkEvents(events) {
3190
3079
  return events.slice(-12).map((event) => {
3191
- const record = asRecord(event);
3192
- const payload = asRecord(record.payload);
3080
+ const payload = asRecord(event.payload);
3193
3081
  return {
3194
- type: normalizeOptionalString(record.type) ?? "unknown",
3195
- turnId: normalizeOptionalString(record.turnId),
3196
- callId: normalizeOptionalString(record.callId),
3197
- final: typeof record.final === "boolean" ? record.final : void 0,
3082
+ type: event.type,
3083
+ turnId: normalizeOptionalString(event.turnId),
3084
+ callId: normalizeOptionalString(event.callId),
3085
+ final: event.final,
3198
3086
  byteLength: asFiniteNumber(payload.byteLength),
3199
3087
  name: normalizeOptionalString(payload.name),
3200
3088
  text: normalizeOptionalString(payload.text),
@@ -3385,7 +3273,7 @@ async function createFaceTimeRuntime(params) {
3385
3273
  }).finally(scheduleOutboundReconciliation);
3386
3274
  const helperResults = readHelperResults(result);
3387
3275
  const cancelled = helperResults.some((entry) => entry.cancelled === true);
3388
- const helpersContacted = typeof result.helpersContacted === "number" ? result.helpersContacted : helperResults.length;
3276
+ const helpersContacted = result.helpersContacted ?? helperResults.length;
3389
3277
  const definitivelyAbsent = helperResults.length === helpersContacted && hasDialHelperConfirmation(helperResults) && helperResults.every((entry) => entry.found === false && entry.cancelled === false);
3390
3278
  if (!cancelled && !definitivelyAbsent) throw new Error("FaceTime helper could not confirm outbound call cancellation");
3391
3279
  const replyCallUUID = helperResults.map(readOutboundCallUUID).find((value) => Boolean(value));
@@ -3412,7 +3300,7 @@ async function createFaceTimeRuntime(params) {
3412
3300
  if (helperStopped) return;
3413
3301
  const outboundIdentity = normalizeFaceTimeOutboundIdentityEvent(message);
3414
3302
  if (outboundIdentity && outboundCallPending?.dialID === outboundIdentity.data.dial_id) {
3415
- if (OUTBOUND_DIAL_HELPER_BUNDLES.has(peer.bundleIdentifier)) outboundCarrierPeers.set(peer.processId, peer);
3303
+ if (DIAL_BUNDLES.has(peer.bundleIdentifier)) outboundCarrierPeers.set(peer.processId, peer);
3416
3304
  retainFaceTimeDialCallUUID(outboundCallPending, outboundIdentity.data.call_uuid);
3417
3305
  if (outboundIdentity.data.proxy_identifier) outboundCallPending.proxyIdentifier = outboundIdentity.data.proxy_identifier;
3418
3306
  return observePendingOperation(persistOutboundCallPending());