22import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime" ;
33import { ErrorCodes , errorShape } from "openclaw/plugin-sdk/gateway-runtime" ;
44import { timestampMsToIsoString } from "openclaw/plugin-sdk/number-runtime" ;
5- import { normalizeAgentId } from "openclaw/plugin-sdk/routing" ;
5+ import { normalizeAgentId , parseAgentSessionKey } from "openclaw/plugin-sdk/routing" ;
66import {
77 asOptionalRecord ,
88 normalizeOptionalString ,
@@ -189,9 +189,6 @@ const VoiceCallToolSchema = Type.Union([
189189 message : Type . String ( { description : "Intro message" } ) ,
190190 mode : Type . Optional ( Type . Union ( [ Type . Literal ( "notify" ) , Type . Literal ( "conversation" ) ] ) ) ,
191191 sessionKey : Type . Optional ( Type . String ( { description : "OpenClaw session key for the call" } ) ) ,
192- requesterSessionKey : Type . Optional (
193- Type . String ( { description : "OpenClaw session key that initiated the call" } ) ,
194- ) ,
195192 dtmfSequence : Type . Optional ( Type . String ( { description : "DTMF digits to play before connect" } ) ) ,
196193 } ) ,
197194 Type . Object ( {
@@ -223,9 +220,6 @@ const VoiceCallToolSchema = Type.Union([
223220 sid : Type . Optional ( Type . String ( { description : "Call SID" } ) ) ,
224221 message : Type . Optional ( Type . String ( { description : "Optional intro message" } ) ) ,
225222 sessionKey : Type . Optional ( Type . String ( { description : "OpenClaw session key for the call" } ) ) ,
226- requesterSessionKey : Type . Optional (
227- Type . String ( { description : "OpenClaw session key that initiated the call" } ) ,
228- ) ,
229223 dtmfSequence : Type . Optional ( Type . String ( { description : "DTMF digits to play before connect" } ) ) ,
230224 } ) ,
231225] ) ;
@@ -723,7 +717,13 @@ export default definePluginEntry({
723717 parameters : VoiceCallToolSchema ,
724718 async execute ( _toolCallId , params ) {
725719 const rawParams = asParamRecord ( params ) ;
726- const agentId = normalizeOptionalString ( toolContext . agentId ) ;
720+ const requesterSessionKey = normalizeOptionalString ( toolContext . sessionKey ) ;
721+ // Agent ownership and requester lineage come from trusted tool context.
722+ // Some harnesses omit agentId but retain its canonical session key.
723+ const contextAgentId =
724+ normalizeOptionalString ( toolContext . agentId ) ??
725+ parseAgentSessionKey ( requesterSessionKey ) ?. agentId ;
726+ const agentId = contextAgentId ? normalizeAgentId ( contextAgentId ) : undefined ;
727727 try {
728728 const rt = await ensureRuntime ( ) ;
729729
@@ -738,15 +738,20 @@ export default definePluginEntry({
738738 if ( ! to ) {
739739 throw new Error ( "to required" ) ;
740740 }
741- const result = await rt . manager . initiateCall ( to , undefined , {
742- message,
743- dtmfSequence : normalizeOptionalString ( rawParams . dtmfSequence ) ,
744- mode :
745- rawParams . mode === "notify" || rawParams . mode === "conversation"
746- ? rawParams . mode
747- : undefined ,
748- ...( agentId ? { agentId } : { } ) ,
749- } ) ;
741+ const result = await rt . manager . initiateCall (
742+ to ,
743+ normalizeOptionalString ( rawParams . sessionKey ) ,
744+ {
745+ message,
746+ dtmfSequence : normalizeOptionalString ( rawParams . dtmfSequence ) ,
747+ mode :
748+ rawParams . mode === "notify" || rawParams . mode === "conversation"
749+ ? rawParams . mode
750+ : undefined ,
751+ ...( agentId ? { agentId } : { } ) ,
752+ ...( requesterSessionKey ? { requesterSessionKey } : { } ) ,
753+ } ,
754+ ) ;
750755 if ( ! result . success ) {
751756 throw new Error ( result . error || "initiate failed" ) ;
752757 }
@@ -833,9 +838,7 @@ export default definePluginEntry({
833838 dtmfSequence : normalizeOptionalString ( rawParams . dtmfSequence ) ,
834839 message : normalizeOptionalString ( rawParams . message ) ,
835840 ...( agentId ? { agentId } : { } ) ,
836- ...( normalizeOptionalString ( rawParams . requesterSessionKey )
837- ? { requesterSessionKey : normalizeOptionalString ( rawParams . requesterSessionKey ) }
838- : { } ) ,
841+ ...( requesterSessionKey ? { requesterSessionKey } : { } ) ,
839842 } ,
840843 ) ;
841844 if ( ! result . success ) {
0 commit comments