@openclaw/facetime 2026.9.8 → 2026.10.1-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.
- package/dist/.setup/{setup-CoxvlB5L.mjs → setup-zO6FazjC.mjs} +9 -19
- package/dist/doctor-contract-api.js +8 -6
- package/dist/index.js +6 -10
- package/dist/runtime-api.js +83 -187
- package/doctor-contract-api.ts +4 -11
- package/index.ts +8 -15
- package/package.json +4 -4
- package/src/audio-pump.ts +4 -15
- package/src/call-events.ts +22 -56
- package/src/call-lifecycle.ts +2 -4
- package/src/config.ts +14 -29
- package/src/helper-results.ts +10 -30
- package/src/helper-rpc.ts +18 -37
- package/src/helper-supervisor.ts +3 -41
- package/src/outbound-call.ts +1 -5
- package/src/plugin-paths.ts +8 -24
- package/src/runtime-call-control.ts +9 -31
- package/src/runtime-call-events.ts +8 -11
- package/src/runtime-helper-results.ts +7 -19
- package/src/runtime-state.ts +17 -54
- package/src/runtime.ts +12 -27
- package/src/talk-driver.ts +19 -25
- package/src/talk-events-summary.ts +6 -6
package/index.ts
CHANGED
|
@@ -82,6 +82,12 @@ const faceTimePlugin: OpenClawPluginDefinition = definePluginEntry({
|
|
|
82
82
|
runCommandWithTimeout: api.runtime.system.runCommandWithTimeout,
|
|
83
83
|
});
|
|
84
84
|
};
|
|
85
|
+
const stopRuntime = () =>
|
|
86
|
+
stopRetainedRuntime(runtimePromise, (stopped) => {
|
|
87
|
+
if (runtimePromise === stopped) {
|
|
88
|
+
runtimePromise = undefined;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
85
91
|
|
|
86
92
|
api.registerTool(() => createFaceTimeCallTool({ ensureRuntime, getStatus }), {
|
|
87
93
|
name: "facetime_call",
|
|
@@ -105,13 +111,7 @@ const faceTimePlugin: OpenClawPluginDefinition = definePluginEntry({
|
|
|
105
111
|
api.logger.warn(`[facetime] startup skipped: ${formatErrorMessage(error)}`);
|
|
106
112
|
}
|
|
107
113
|
},
|
|
108
|
-
|
|
109
|
-
await stopRetainedRuntime(runtimePromise, (stopped) => {
|
|
110
|
-
if (runtimePromise === stopped) {
|
|
111
|
-
runtimePromise = undefined;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
},
|
|
114
|
+
stop: stopRuntime,
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
const registerGateway = (
|
|
@@ -180,14 +180,7 @@ const faceTimePlugin: OpenClawPluginDefinition = definePluginEntry({
|
|
|
180
180
|
}
|
|
181
181
|
uninstalling = true;
|
|
182
182
|
try {
|
|
183
|
-
|
|
184
|
-
if (current) {
|
|
185
|
-
await stopRetainedRuntime(current, (stopped) => {
|
|
186
|
-
if (runtimePromise === stopped) {
|
|
187
|
-
runtimePromise = undefined;
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
}
|
|
183
|
+
await stopRuntime();
|
|
191
184
|
await uninstallFaceTimeDriver({
|
|
192
185
|
pluginRoot,
|
|
193
186
|
runCommandWithTimeout: api.runtime.system.runCommandWithTimeout,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/facetime",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.10.1-beta.1",
|
|
4
4
|
"description": "Experimental FaceTime realtime voice carrier for OpenClaw agents",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "OpenClaw contributors",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"typebox": "1.3.34"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"openclaw": ">=2026.
|
|
69
|
+
"openclaw": ">=2026.10.1-beta.1"
|
|
70
70
|
},
|
|
71
71
|
"peerDependenciesMeta": {
|
|
72
72
|
"openclaw": {
|
|
@@ -85,11 +85,11 @@
|
|
|
85
85
|
"allowInvalidConfigRecovery": true
|
|
86
86
|
},
|
|
87
87
|
"compat": {
|
|
88
|
-
"pluginApi": ">=2026.
|
|
88
|
+
"pluginApi": ">=2026.10.1-beta.1"
|
|
89
89
|
},
|
|
90
90
|
"build": {
|
|
91
91
|
"bundledDist": false,
|
|
92
|
-
"openclawVersion": "2026.
|
|
92
|
+
"openclawVersion": "2026.10.1-beta.1"
|
|
93
93
|
},
|
|
94
94
|
"release": {
|
|
95
95
|
"publishToClawHub": true,
|
package/src/audio-pump.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
RealtimeVoiceAudioChunkMetadata,
|
|
9
9
|
RealtimeVoicePlaybackItem,
|
|
10
10
|
} from "openclaw/plugin-sdk/realtime-voice";
|
|
11
|
+
import { sleepWithAbort } from "openclaw/plugin-sdk/runtime-env";
|
|
11
12
|
|
|
12
13
|
type PumpProcess = {
|
|
13
14
|
pid?: number;
|
|
@@ -52,7 +53,7 @@ const MAX_PLAYBACK_BUFFERED_BYTES = 2 * 1024 * 1024;
|
|
|
52
53
|
type FaceTimeAudioPump = {
|
|
53
54
|
suppressionReady(): Promise<void>;
|
|
54
55
|
routeReady(): Promise<void>;
|
|
55
|
-
processOutputSuppressed(): boolean;
|
|
56
|
+
processOutputSuppressed(this: void): boolean;
|
|
56
57
|
writeOutputAudio(audio: Buffer, metadata?: RealtimeVoiceAudioChunkMetadata): void;
|
|
57
58
|
getPlaybackState(): RealtimeVoicePlaybackItem[];
|
|
58
59
|
finishOutputAudio(): void;
|
|
@@ -181,26 +182,14 @@ async function terminateProcess(proc: PumpProcess, signal: NodeJS.Signals = "SIG
|
|
|
181
182
|
} catch {
|
|
182
183
|
return;
|
|
183
184
|
}
|
|
184
|
-
await Promise.race([
|
|
185
|
-
exitedPromise,
|
|
186
|
-
new Promise<void>((resolve) => {
|
|
187
|
-
const timer = setTimeout(resolve, 500);
|
|
188
|
-
timer.unref?.();
|
|
189
|
-
}),
|
|
190
|
-
]);
|
|
185
|
+
await Promise.race([exitedPromise, sleepWithAbort(500, undefined, { ref: false })]);
|
|
191
186
|
if (!exited && signal !== "SIGKILL") {
|
|
192
187
|
try {
|
|
193
188
|
proc.kill("SIGKILL");
|
|
194
189
|
} catch {
|
|
195
190
|
return;
|
|
196
191
|
}
|
|
197
|
-
await Promise.race([
|
|
198
|
-
exitedPromise,
|
|
199
|
-
new Promise<void>((resolve) => {
|
|
200
|
-
const timer = setTimeout(resolve, 500);
|
|
201
|
-
timer.unref?.();
|
|
202
|
-
}),
|
|
203
|
-
]);
|
|
192
|
+
await Promise.race([exitedPromise, sleepWithAbort(500, undefined, { ref: false })]);
|
|
204
193
|
}
|
|
205
194
|
}
|
|
206
195
|
|
package/src/call-events.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
asBoolean,
|
|
3
|
+
asFiniteNumber,
|
|
3
4
|
asRecord,
|
|
4
5
|
normalizeOptionalString,
|
|
5
6
|
} from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
@@ -10,31 +11,26 @@ export type FaceTimeCallStatusEvent = {
|
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
type FaceTimeCallStatusData = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
call_uuid?: unknown;
|
|
14
|
+
call_status: number;
|
|
15
|
+
call_uuid: string;
|
|
16
16
|
dial_id?: unknown;
|
|
17
|
-
proxy_identifier?:
|
|
18
|
-
conversation_group_uuid?:
|
|
19
|
-
conversation_uuid?:
|
|
20
|
-
conversation_audio_enabled?:
|
|
21
|
-
conversation_video_enabled?:
|
|
22
|
-
conversation_av_mode?:
|
|
23
|
-
conversation_resolved_audio_video_mode?:
|
|
24
|
-
|
|
25
|
-
ended_error?: unknown;
|
|
26
|
-
ended_reason?: unknown;
|
|
27
|
-
has_ended?: unknown;
|
|
17
|
+
proxy_identifier?: string;
|
|
18
|
+
conversation_group_uuid?: string;
|
|
19
|
+
conversation_uuid?: string;
|
|
20
|
+
conversation_audio_enabled?: boolean;
|
|
21
|
+
conversation_video_enabled?: boolean;
|
|
22
|
+
conversation_av_mode?: number;
|
|
23
|
+
conversation_resolved_audio_video_mode?: number;
|
|
24
|
+
has_ended?: boolean;
|
|
28
25
|
handle?: unknown;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
transport?: unknown;
|
|
26
|
+
is_outgoing?: boolean;
|
|
27
|
+
is_sending_audio?: boolean;
|
|
28
|
+
is_sending_transmission?: boolean;
|
|
29
|
+
is_sending_video?: boolean;
|
|
30
|
+
is_uplink_muted?: boolean;
|
|
31
|
+
local_meter_level?: number;
|
|
32
|
+
remote_meter_level?: number;
|
|
33
|
+
transport?: ReturnType<typeof normalizeCallTransport>;
|
|
38
34
|
};
|
|
39
35
|
|
|
40
36
|
// Verified against the current TelephonyUtilities TUCall state machine. Native
|
|
@@ -46,43 +42,13 @@ const TU_CALL_STATUS = {
|
|
|
46
42
|
incomingRinging: 4,
|
|
47
43
|
} as const;
|
|
48
44
|
|
|
49
|
-
type FaceTimeCallTransport =
|
|
50
|
-
| {
|
|
51
|
-
kind: "facetime";
|
|
52
|
-
classifierVersion: "tu-provider-v1";
|
|
53
|
-
service: 2 | 3;
|
|
54
|
-
faceTimeTransportType?: number;
|
|
55
|
-
providerClassified: true;
|
|
56
|
-
providerIsFaceTime: true;
|
|
57
|
-
providerIsTelephony: false;
|
|
58
|
-
isUsingBaseband: false;
|
|
59
|
-
isWifiCall: false;
|
|
60
|
-
isVoip: true;
|
|
61
|
-
isEmergency: false;
|
|
62
|
-
}
|
|
63
|
-
| {
|
|
64
|
-
kind: "cellular" | "unknown";
|
|
65
|
-
classifierVersion: "tu-provider-v1";
|
|
66
|
-
service?: number;
|
|
67
|
-
faceTimeTransportType?: number;
|
|
68
|
-
providerClassified?: boolean;
|
|
69
|
-
providerIsFaceTime?: boolean;
|
|
70
|
-
providerIsTelephony?: boolean;
|
|
71
|
-
isUsingBaseband?: boolean;
|
|
72
|
-
isWifiCall?: boolean;
|
|
73
|
-
isVoip?: boolean;
|
|
74
|
-
isEmergency?: boolean;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
45
|
export type AuthenticatedFaceTimeOwner = {
|
|
78
46
|
senderId: string;
|
|
79
47
|
senderIsOwner: true;
|
|
80
48
|
};
|
|
81
49
|
|
|
82
50
|
function readFiniteNumber(value: unknown): number | undefined {
|
|
83
|
-
|
|
84
|
-
typeof value === "number" ? value : typeof value === "string" ? Number(value) : Number.NaN;
|
|
85
|
-
return Number.isFinite(number) ? number : undefined;
|
|
51
|
+
return asFiniteNumber(typeof value === "string" ? Number(value) : value);
|
|
86
52
|
}
|
|
87
53
|
|
|
88
54
|
function readInteger(value: unknown): number | undefined {
|
|
@@ -90,7 +56,7 @@ function readInteger(value: unknown): number | undefined {
|
|
|
90
56
|
return Number.isInteger(number) ? number : undefined;
|
|
91
57
|
}
|
|
92
58
|
|
|
93
|
-
function normalizeCallTransport(value: unknown)
|
|
59
|
+
function normalizeCallTransport(value: unknown) {
|
|
94
60
|
const transport = asRecord(value);
|
|
95
61
|
const base = {
|
|
96
62
|
classifierVersion: "tu-provider-v1" as const,
|
|
@@ -274,7 +240,7 @@ export function resolveAuthorizedFaceTimeOwner(params: {
|
|
|
274
240
|
}
|
|
275
241
|
|
|
276
242
|
export function isVerifiedFaceTimeTransport(event: FaceTimeCallStatusEvent): boolean {
|
|
277
|
-
return
|
|
243
|
+
return event.data.transport?.kind === "facetime";
|
|
278
244
|
}
|
|
279
245
|
|
|
280
246
|
export function isVerifiedFaceTimeTransportEvidence(value: unknown): boolean {
|
package/src/call-lifecycle.ts
CHANGED
|
@@ -50,10 +50,8 @@ export class FaceTimeCallInstance {
|
|
|
50
50
|
action: () => Promise<T>;
|
|
51
51
|
}): Promise<T> {
|
|
52
52
|
const previous = this.#commandTail;
|
|
53
|
-
|
|
54
|
-
this.#commandTail =
|
|
55
|
-
release = resolve;
|
|
56
|
-
});
|
|
53
|
+
const { promise, resolve: release } = createDeferred<void>();
|
|
54
|
+
this.#commandTail = promise;
|
|
57
55
|
await previous;
|
|
58
56
|
try {
|
|
59
57
|
this.assertCurrent(params.generation, params.allowClosing);
|
package/src/config.ts
CHANGED
|
@@ -3,20 +3,18 @@ import {
|
|
|
3
3
|
REALTIME_VOICE_AGENT_CONSULT_TOOL_POLICIES,
|
|
4
4
|
type RealtimeVoiceAgentConsultToolPolicy,
|
|
5
5
|
} from "openclaw/plugin-sdk/realtime-voice";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
asBoolean,
|
|
8
|
+
asRecord,
|
|
9
|
+
normalizeOptionalString,
|
|
10
|
+
normalizeTrimmedStringList,
|
|
11
|
+
} from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
realtime:
|
|
12
|
-
|
|
13
|
-
model?: string;
|
|
14
|
-
voice?: string;
|
|
15
|
-
sessionKey: string;
|
|
16
|
-
toolPolicy: RealtimeVoiceAgentConsultToolPolicy;
|
|
17
|
-
instructions?: string;
|
|
18
|
-
providers: Record<string, Record<string, unknown>>;
|
|
19
|
-
};
|
|
13
|
+
type ProducedFaceTimeConfig = ReturnType<typeof resolveFaceTimeConfig>;
|
|
14
|
+
type OptionalRealtimeFields = "provider" | "model" | "voice" | "instructions";
|
|
15
|
+
export type FaceTimeConfig = Omit<ProducedFaceTimeConfig, "realtime"> & {
|
|
16
|
+
realtime: Omit<ProducedFaceTimeConfig["realtime"], OptionalRealtimeFields> &
|
|
17
|
+
Partial<Pick<ProducedFaceTimeConfig["realtime"], OptionalRealtimeFields>>;
|
|
20
18
|
};
|
|
21
19
|
|
|
22
20
|
const DEFAULT_INSTRUCTIONS = [
|
|
@@ -24,19 +22,6 @@ const DEFAULT_INSTRUCTIONS = [
|
|
|
24
22
|
"Keep replies concise, natural, and useful for a hands-free voice conversation.",
|
|
25
23
|
].join(" ");
|
|
26
24
|
|
|
27
|
-
function resolveBoolean(value: unknown, fallback: boolean): boolean {
|
|
28
|
-
return typeof value === "boolean" ? value : fallback;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function resolveStringArray(value: unknown): string[] {
|
|
32
|
-
if (!Array.isArray(value)) {
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
return value
|
|
36
|
-
.map((entry) => normalizeOptionalString(entry))
|
|
37
|
-
.filter((entry): entry is string => Boolean(entry));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
25
|
function resolveRealtimeVoiceAgentConsultToolPolicy(
|
|
41
26
|
value: unknown,
|
|
42
27
|
): RealtimeVoiceAgentConsultToolPolicy {
|
|
@@ -64,15 +49,15 @@ function resolveProviders(value: unknown): Record<string, Record<string, unknown
|
|
|
64
49
|
return providers;
|
|
65
50
|
}
|
|
66
51
|
|
|
67
|
-
export function resolveFaceTimeConfig(input: unknown)
|
|
52
|
+
export function resolveFaceTimeConfig(input: unknown) {
|
|
68
53
|
const raw = asRecord(input);
|
|
69
54
|
const realtime = asRecord(raw.realtime);
|
|
70
55
|
if (typeof realtime.instructions === "string" && realtime.instructions.length > 4000) {
|
|
71
56
|
throw new Error("realtime.instructions must not exceed 4000 characters");
|
|
72
57
|
}
|
|
73
58
|
return {
|
|
74
|
-
enabled:
|
|
75
|
-
ownerHandles:
|
|
59
|
+
enabled: asBoolean(raw.enabled) ?? true,
|
|
60
|
+
ownerHandles: normalizeTrimmedStringList(raw.ownerHandles),
|
|
76
61
|
realtime: {
|
|
77
62
|
provider: normalizeOptionalString(realtime.provider),
|
|
78
63
|
model: normalizeOptionalString(realtime.model),
|
package/src/helper-results.ts
CHANGED
|
@@ -63,50 +63,30 @@ export function projectFaceTimeNativeAction(
|
|
|
63
63
|
throw new FaceTimeHelperAmbiguousError(`FaceTime ${action} carrier owner is missing`, result);
|
|
64
64
|
}
|
|
65
65
|
if (
|
|
66
|
-
action === "unmute" &&
|
|
66
|
+
(action === "unmute" || action === "activate") &&
|
|
67
67
|
present.every(
|
|
68
68
|
(observed) =>
|
|
69
69
|
observed.muted === false &&
|
|
70
70
|
observed.is_uplink_muted === false &&
|
|
71
|
-
typeof observed.conversation_audio_error !== "string"
|
|
71
|
+
typeof observed.conversation_audio_error !== "string" &&
|
|
72
|
+
(action === "unmute" ||
|
|
73
|
+
(observed.is_sending_audio === true && observed.is_sending_transmission === true)),
|
|
72
74
|
)
|
|
73
75
|
) {
|
|
74
76
|
return { status: "media-active" };
|
|
75
77
|
}
|
|
76
78
|
if (
|
|
77
|
-
action === "answer" &&
|
|
79
|
+
(action === "answer" || action === "safe-mute") &&
|
|
78
80
|
present.every(
|
|
79
81
|
(observed) =>
|
|
80
|
-
observed.outcome === "answered-muted" &&
|
|
81
82
|
observed.muted === true &&
|
|
82
|
-
observed.is_uplink_muted === true
|
|
83
|
+
observed.is_uplink_muted === true &&
|
|
84
|
+
(action === "answer"
|
|
85
|
+
? observed.outcome === "answered-muted"
|
|
86
|
+
: observed.downlink_muted === true),
|
|
83
87
|
)
|
|
84
88
|
) {
|
|
85
|
-
return { status: "answered-muted" };
|
|
86
|
-
}
|
|
87
|
-
if (
|
|
88
|
-
action === "safe-mute" &&
|
|
89
|
-
present.every(
|
|
90
|
-
(observed) =>
|
|
91
|
-
observed.downlink_muted === true &&
|
|
92
|
-
observed.muted === true &&
|
|
93
|
-
observed.is_uplink_muted === true,
|
|
94
|
-
)
|
|
95
|
-
) {
|
|
96
|
-
return { status: "safe-muted" };
|
|
97
|
-
}
|
|
98
|
-
if (
|
|
99
|
-
action === "activate" &&
|
|
100
|
-
present.every(
|
|
101
|
-
(observed) =>
|
|
102
|
-
observed.muted === false &&
|
|
103
|
-
observed.is_uplink_muted === false &&
|
|
104
|
-
observed.is_sending_audio === true &&
|
|
105
|
-
observed.is_sending_transmission === true &&
|
|
106
|
-
typeof observed.conversation_audio_error !== "string",
|
|
107
|
-
)
|
|
108
|
-
) {
|
|
109
|
-
return { status: "media-active" };
|
|
89
|
+
return { status: action === "answer" ? "answered-muted" : "safe-muted" };
|
|
110
90
|
}
|
|
111
91
|
if (
|
|
112
92
|
action === "terminate" &&
|
package/src/helper-rpc.ts
CHANGED
|
@@ -11,15 +11,6 @@ import {
|
|
|
11
11
|
} from "./helper-results.js";
|
|
12
12
|
import type { FaceTimeDialRequest } from "./outbound-call.js";
|
|
13
13
|
|
|
14
|
-
export {
|
|
15
|
-
FaceTimeHelperAmbiguousError,
|
|
16
|
-
FaceTimeHelperUnavailableError,
|
|
17
|
-
projectCompleteFaceTimeAbsence,
|
|
18
|
-
projectFaceTimeNativeAction,
|
|
19
|
-
readHelperResults,
|
|
20
|
-
type HelperActionResult,
|
|
21
|
-
} from "./helper-results.js";
|
|
22
|
-
|
|
23
14
|
type HelperSocketServerParams = {
|
|
24
15
|
host: string;
|
|
25
16
|
port: number;
|
|
@@ -78,8 +69,6 @@ type PendingHelperHandshake = {
|
|
|
78
69
|
bundleIdentifier: string;
|
|
79
70
|
processId: number;
|
|
80
71
|
processStartedAtMs: number;
|
|
81
|
-
clientNonce: string;
|
|
82
|
-
serverNonce: string;
|
|
83
72
|
connectionEpoch: string;
|
|
84
73
|
connectionKey: string;
|
|
85
74
|
};
|
|
@@ -103,12 +92,10 @@ export class FaceTimeHelperSocketServer {
|
|
|
103
92
|
readonly #socketAuthSessions = new Map<net.Socket, HelperAuthSession>();
|
|
104
93
|
readonly #authDeadlineTimers = new Map<net.Socket, ReturnType<typeof setTimeout>>();
|
|
105
94
|
readonly #pending = new Map<string, PendingRpc>();
|
|
106
|
-
readonly #logger: RuntimeLogger;
|
|
107
95
|
#started = false;
|
|
108
96
|
#connectionGeneration = 0;
|
|
109
97
|
|
|
110
98
|
constructor(private readonly params: HelperSocketServerParams) {
|
|
111
|
-
this.#logger = params.logger;
|
|
112
99
|
this.#server = net.createServer((socket) => this.#handleSocket(socket));
|
|
113
100
|
}
|
|
114
101
|
|
|
@@ -264,7 +251,7 @@ export class FaceTimeHelperSocketServer {
|
|
|
264
251
|
}
|
|
265
252
|
});
|
|
266
253
|
socket.on("error", (error) => {
|
|
267
|
-
this
|
|
254
|
+
this.params.logger.debug?.(`[facetime] helper socket error: ${formatErrorMessage(error)}`);
|
|
268
255
|
});
|
|
269
256
|
socket.on("close", () => {
|
|
270
257
|
const disconnectedBundle = this.#socketPeers.get(socket)?.bundleIdentifier;
|
|
@@ -291,7 +278,9 @@ export class FaceTimeHelperSocketServer {
|
|
|
291
278
|
try {
|
|
292
279
|
parsed = JSON.parse(line);
|
|
293
280
|
} catch (error) {
|
|
294
|
-
this
|
|
281
|
+
this.params.logger.debug?.(
|
|
282
|
+
`[facetime] rejected invalid helper JSON: ${formatErrorMessage(error)}`,
|
|
283
|
+
);
|
|
295
284
|
socket.destroy();
|
|
296
285
|
return;
|
|
297
286
|
}
|
|
@@ -307,7 +296,7 @@ export class FaceTimeHelperSocketServer {
|
|
|
307
296
|
|
|
308
297
|
const payload = this.#consumeHelperEnvelope(socket, record);
|
|
309
298
|
if (!payload) {
|
|
310
|
-
this
|
|
299
|
+
this.params.logger.warn?.("[facetime] rejected unauthenticated or replayed helper message");
|
|
311
300
|
socket.destroy();
|
|
312
301
|
return;
|
|
313
302
|
}
|
|
@@ -321,20 +310,18 @@ export class FaceTimeHelperSocketServer {
|
|
|
321
310
|
}
|
|
322
311
|
|
|
323
312
|
const transactionId = typeof payload.transactionId === "string" ? payload.transactionId : "";
|
|
324
|
-
|
|
325
|
-
|
|
313
|
+
const pending = transactionId ? this.#pending.get(transactionId) : undefined;
|
|
314
|
+
if (pending) {
|
|
326
315
|
this.#pending.delete(transactionId);
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
payload.
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
pending.resolve(payload);
|
|
337
|
-
}
|
|
316
|
+
clearTimeout(pending.timeout);
|
|
317
|
+
if (typeof payload.error === "string" && payload.error) {
|
|
318
|
+
pending.reject(
|
|
319
|
+
payload.ambiguous === true
|
|
320
|
+
? new FaceTimeHelperAmbiguousError(payload.error, payload)
|
|
321
|
+
: new FaceTimeHelperActionError(payload.error),
|
|
322
|
+
);
|
|
323
|
+
} else {
|
|
324
|
+
pending.resolve(payload);
|
|
338
325
|
}
|
|
339
326
|
return;
|
|
340
327
|
}
|
|
@@ -401,8 +388,6 @@ export class FaceTimeHelperSocketServer {
|
|
|
401
388
|
bundleIdentifier,
|
|
402
389
|
processId,
|
|
403
390
|
processStartedAtMs,
|
|
404
|
-
clientNonce,
|
|
405
|
-
serverNonce,
|
|
406
391
|
connectionEpoch,
|
|
407
392
|
connectionKey: helperHmac(this.params.ipcKey, `session\n${context}`),
|
|
408
393
|
};
|
|
@@ -507,7 +492,7 @@ export class FaceTimeHelperSocketServer {
|
|
|
507
492
|
return payloadRecord;
|
|
508
493
|
}
|
|
509
494
|
|
|
510
|
-
#writeServerPayload(socket: net.Socket, payload: Record<string, unknown>):
|
|
495
|
+
#writeServerPayload(socket: net.Socket, payload: Record<string, unknown>): void {
|
|
511
496
|
const session = this.#socketAuthSessions.get(socket);
|
|
512
497
|
if (!session) {
|
|
513
498
|
throw new FaceTimeHelperUnavailableError("FaceTime helper socket is not authenticated");
|
|
@@ -529,7 +514,6 @@ export class FaceTimeHelperSocketServer {
|
|
|
529
514
|
}
|
|
530
515
|
session.outgoingSequence = sequence;
|
|
531
516
|
socket.write(`${envelope}\r\n`);
|
|
532
|
-
return envelope;
|
|
533
517
|
}
|
|
534
518
|
|
|
535
519
|
async #sendAction(action: string, data: Record<string, unknown>): Promise<HelperActionResult> {
|
|
@@ -583,10 +567,7 @@ export class FaceTimeHelperSocketServer {
|
|
|
583
567
|
);
|
|
584
568
|
if (fulfilled.length > 0) {
|
|
585
569
|
const fulfilledProcessIds = new Set(
|
|
586
|
-
fulfilled.flatMap((
|
|
587
|
-
const peer = result.helperPeer;
|
|
588
|
-
return peer && typeof peer === "object" && "processId" in peer ? [peer.processId] : [];
|
|
589
|
-
}),
|
|
570
|
+
fulfilled.flatMap(({ helperPeer }) => (helperPeer ? [helperPeer.processId] : [])),
|
|
590
571
|
);
|
|
591
572
|
return {
|
|
592
573
|
helpersContacted: sockets.length,
|
package/src/helper-supervisor.ts
CHANGED
|
@@ -40,10 +40,6 @@ const TARGET_APP_PATHS: Record<FaceTimeHelperTarget, string> = {
|
|
|
40
40
|
FaceTime: "/System/Applications/FaceTime.app",
|
|
41
41
|
Phone: "/System/Applications/Phone.app",
|
|
42
42
|
};
|
|
43
|
-
const TARGET_EXECUTABLES: Record<FaceTimeHelperTarget, string> = {
|
|
44
|
-
FaceTime: "/System/Applications/FaceTime.app/Contents/MacOS/FaceTime",
|
|
45
|
-
Phone: "/System/Applications/Phone.app/Contents/MacOS/Phone",
|
|
46
|
-
};
|
|
47
43
|
const FACETIME_HELPER_TARGETS = ["FaceTime", "Phone"] as const;
|
|
48
44
|
|
|
49
45
|
const DEFAULT_RETRY_DELAYS_MS = [1_000, 2_000, 5_000, 10_000, 30_000, 60_000] as const;
|
|
@@ -144,28 +140,22 @@ export class FaceTimeHelperSupervisor {
|
|
|
144
140
|
if (!target || !state) {
|
|
145
141
|
return;
|
|
146
142
|
}
|
|
147
|
-
const staleProcessId = processId > 0 ? processId : undefined;
|
|
148
143
|
const wasStale = state.stale;
|
|
149
144
|
// A stale helper reconnects every five seconds until its host app exits.
|
|
150
145
|
// Treat the whole stale episode as one operator action so reconnects from
|
|
151
146
|
// the app or its services cannot flood logs. An identical callback also
|
|
152
147
|
// keeps the existing process-exit monitor's original deadline.
|
|
153
|
-
if (state.stale && state.staleProcessId ===
|
|
148
|
+
if (state.stale && state.staleProcessId === processId) {
|
|
154
149
|
return;
|
|
155
150
|
}
|
|
156
151
|
state.connected = false;
|
|
157
152
|
state.stale = true;
|
|
158
|
-
state.staleProcessId =
|
|
153
|
+
state.staleProcessId = processId;
|
|
159
154
|
state.lastError = `Restart ${target} to load the updated OpenClaw helper`;
|
|
160
155
|
if (!wasStale) {
|
|
161
156
|
this.params.logger.warn(`[facetime] ${state.lastError}`);
|
|
162
157
|
}
|
|
163
|
-
|
|
164
|
-
this.#scheduleStaleProcessCheck(target, processId);
|
|
165
|
-
} else {
|
|
166
|
-
this.#cancelTimer(target);
|
|
167
|
-
void this.#resolveLegacyStaleProcess(target);
|
|
168
|
-
}
|
|
158
|
+
this.#scheduleStaleProcessCheck(target, processId);
|
|
169
159
|
}
|
|
170
160
|
|
|
171
161
|
status(): FaceTimeHelperSupervisorStatus {
|
|
@@ -242,34 +232,6 @@ export class FaceTimeHelperSupervisor {
|
|
|
242
232
|
this.#timers.set(target, timer);
|
|
243
233
|
}
|
|
244
234
|
|
|
245
|
-
async #resolveLegacyStaleProcess(target: FaceTimeHelperTarget): Promise<void> {
|
|
246
|
-
const state = this.#states.get(target);
|
|
247
|
-
if (!this.#started || !state?.stale || state.staleProcessId !== undefined) {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
try {
|
|
251
|
-
const result = await this.params.runCommandWithTimeout(
|
|
252
|
-
["/usr/bin/pgrep", "-f", TARGET_EXECUTABLES[target]],
|
|
253
|
-
{ timeoutMs: 5_000 },
|
|
254
|
-
);
|
|
255
|
-
const processId = Number.parseInt(result.stdout.trim().split(/\s+/u)[0] ?? "", 10);
|
|
256
|
-
if (result.code === 0 && Number.isSafeInteger(processId) && processId > 0) {
|
|
257
|
-
state.staleProcessId = processId;
|
|
258
|
-
this.#scheduleStaleProcessCheck(target, processId);
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
} catch (error) {
|
|
262
|
-
this.params.logger.debug?.(
|
|
263
|
-
`[facetime] failed to resolve stale ${target} helper process: ${formatErrorMessage(error)}`,
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
if (this.#started && state.stale && state.staleProcessId === undefined) {
|
|
267
|
-
state.stale = false;
|
|
268
|
-
state.lastError = undefined;
|
|
269
|
-
this.#schedule(target, 0);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
235
|
#enqueueInjection(target: FaceTimeHelperTarget): void {
|
|
274
236
|
const state = this.#states.get(target);
|
|
275
237
|
if (!state || state.queued || state.injecting) {
|
package/src/outbound-call.ts
CHANGED
|
@@ -157,11 +157,7 @@ export function doesFaceTimeCallMatchPendingDial(params: {
|
|
|
157
157
|
return params.event.data.dial_id === params.pending.dialID;
|
|
158
158
|
}
|
|
159
159
|
if (params.pending.callUUID) {
|
|
160
|
-
|
|
161
|
-
return (
|
|
162
|
-
typeof eventCallUUID === "string" &&
|
|
163
|
-
doesPendingFaceTimeDialHaveCallUUID(params.pending, eventCallUUID)
|
|
164
|
-
);
|
|
160
|
+
return doesPendingFaceTimeDialHaveCallUUID(params.pending, params.event.data.call_uuid);
|
|
165
161
|
}
|
|
166
162
|
if (params.pending.proxyIdentifier) {
|
|
167
163
|
return params.event.data.proxy_identifier === params.pending.proxyIdentifier;
|
package/src/plugin-paths.ts
CHANGED
|
@@ -23,26 +23,8 @@ function resolveHelperDylib(): string {
|
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function
|
|
27
|
-
return resolve(
|
|
28
|
-
homedir(),
|
|
29
|
-
"Library",
|
|
30
|
-
"Application Support",
|
|
31
|
-
"OpenClaw",
|
|
32
|
-
"FaceTime",
|
|
33
|
-
"helper-ipc-key",
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function resolveHelperBuildStamp(): string {
|
|
38
|
-
return resolve(
|
|
39
|
-
homedir(),
|
|
40
|
-
"Library",
|
|
41
|
-
"Application Support",
|
|
42
|
-
"OpenClaw",
|
|
43
|
-
"FaceTime",
|
|
44
|
-
"helper-build.sha256",
|
|
45
|
-
);
|
|
26
|
+
function resolveHelperStateFile(name: "helper-ipc-key" | "helper-build.sha256"): string {
|
|
27
|
+
return resolve(homedir(), "Library", "Application Support", "OpenClaw", "FaceTime", name);
|
|
46
28
|
}
|
|
47
29
|
|
|
48
30
|
async function resolveNativeInstall(params: {
|
|
@@ -132,8 +114,8 @@ export async function inspectFaceTimeArtifacts(params: {
|
|
|
132
114
|
] = await Promise.all([
|
|
133
115
|
inspectFaceTimeNativePackage(params),
|
|
134
116
|
readable(resolveHelperDylib(), constants.R_OK),
|
|
135
|
-
readable(
|
|
136
|
-
readable(
|
|
117
|
+
readable(resolveHelperStateFile("helper-ipc-key"), constants.R_OK),
|
|
118
|
+
readable(resolveHelperStateFile("helper-build.sha256"), constants.R_OK),
|
|
137
119
|
Promise.all(helperTempDirs.map(countHelpers)).then((counts) =>
|
|
138
120
|
counts.reduce((total, count) => total + count, 0),
|
|
139
121
|
),
|
|
@@ -189,8 +171,10 @@ export async function ensureHelperArtifacts(params: {
|
|
|
189
171
|
const loadFile = params.readFile ?? readFile;
|
|
190
172
|
const dylib = resolveHelperDylib();
|
|
191
173
|
await checkAccess(dylib, constants.R_OK);
|
|
192
|
-
const ipcKey = (await loadFile(
|
|
193
|
-
const stagedBuildId = (
|
|
174
|
+
const ipcKey = (await loadFile(resolveHelperStateFile("helper-ipc-key"), "utf8")).trim();
|
|
175
|
+
const stagedBuildId = (
|
|
176
|
+
await loadFile(resolveHelperStateFile("helper-build.sha256"), "utf8")
|
|
177
|
+
).trim();
|
|
194
178
|
if (!/^[\da-f]{64}$/u.test(ipcKey)) {
|
|
195
179
|
throw new Error("FaceTime helper produced an invalid IPC authentication key");
|
|
196
180
|
}
|