fix: omit gateway metadata in local session mode

This commit is contained in:
Haitao Pan 2026-04-06 14:08:46 +08:00
parent bbe4e10371
commit fecc01da0d
2 changed files with 33 additions and 1 deletions

View File

@ -214,7 +214,8 @@ class GoAgentCoreSessionRequest {
if (_usesGatewaySessionMode(mode)) ...<String, dynamic>{
'executionTarget': target.promptValue,
if (agentId.trim().isNotEmpty) 'agentId': agentId.trim(),
if (metadata.isNotEmpty) 'metadata': metadata,
if (metadata.isNotEmpty && _supportsGatewayMetadata(target))
'metadata': metadata,
},
};
return params;
@ -228,6 +229,10 @@ bool _usesGatewaySessionMode(String mode) {
return normalized == 'gateway' || normalized == _gatewaySessionMode;
}
bool _supportsGatewayMetadata(AssistantExecutionTarget target) {
return target == AssistantExecutionTarget.remote;
}
class GoAgentCoreSessionUpdate {
const GoAgentCoreSessionUpdate({
required this.sessionId,

View File

@ -120,6 +120,33 @@ void main() {
expect(params['mode'], 'gateway-chat');
expect(params['executionTarget'], 'local');
expect(params['agentId'], 'agent-1');
expect(params.containsKey('metadata'), isFalse);
});
test('remote gateway mode keeps dispatch metadata in ACP params', () {
const request = GoAgentCoreSessionRequest(
sessionId: 'session-3',
threadId: 'thread-3',
target: AssistantExecutionTarget.remote,
prompt: 'route remotely',
workingDirectory: '/tmp/workspace',
model: '',
thinking: '',
selectedSkills: <String>[],
inlineAttachments: <GatewayChatAttachmentPayload>[],
localAttachments: <CollaborationAttachment>[],
aiGatewayBaseUrl: '',
aiGatewayApiKey: '',
agentId: 'agent-remote',
metadata: <String, dynamic>{'source': 'test'},
provider: SingleAgentProvider.auto,
);
final params = request.toAcpParams();
expect(params['mode'], 'gateway-chat');
expect(params['executionTarget'], 'remote');
expect(params['metadata'], <String, dynamic>{'source': 'test'});
});
test(