From 5316352e438b307d0fd5cc16eba147dd13dbe2e9 Mon Sep 17 00:00:00 2001 From: Wanlin Du Date: Wed, 17 Sep 2025 12:21:30 -0700 Subject: [PATCH] feat: generate function_response's converter PiperOrigin-RevId: 808250364 --- src/converters/_batches_converters.ts | 102 ++++++++-- src/converters/_caches_converters.ts | 102 ++++++++-- src/converters/_live_converters.ts | 268 +++++++++++++++++--------- src/converters/_models_converters.ts | 204 +++++++++++++++++--- src/converters/_tokens_converters.ts | 51 ++++- src/types.ts | 72 +++---- 6 files changed, 608 insertions(+), 191 deletions(-) diff --git a/src/converters/_batches_converters.ts b/src/converters/_batches_converters.ts index 13661fbd1..59d4624f7 100644 --- a/src/converters/_batches_converters.ts +++ b/src/converters/_batches_converters.ts @@ -99,6 +99,39 @@ export function functionCallToMldev( return toObject; } +export function functionResponseToMldev( + fromObject: types.FunctionResponse, +): Record { + const toObject: Record = {}; + + const fromWillContinue = common.getValueByPath(fromObject, ['willContinue']); + if (fromWillContinue != null) { + common.setValueByPath(toObject, ['willContinue'], fromWillContinue); + } + + const fromScheduling = common.getValueByPath(fromObject, ['scheduling']); + if (fromScheduling != null) { + common.setValueByPath(toObject, ['scheduling'], fromScheduling); + } + + const fromId = common.getValueByPath(fromObject, ['id']); + if (fromId != null) { + common.setValueByPath(toObject, ['id'], fromId); + } + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['name'], fromName); + } + + const fromResponse = common.getValueByPath(fromObject, ['response']); + if (fromResponse != null) { + common.setValueByPath(toObject, ['response'], fromResponse); + } + + return toObject; +} + export function partToMldev(fromObject: types.Part): Record { const toObject: Record = {}; @@ -152,6 +185,17 @@ export function partToMldev(fromObject: types.Part): Record { ); } + const fromFunctionResponse = common.getValueByPath(fromObject, [ + 'functionResponse', + ]); + if (fromFunctionResponse != null) { + common.setValueByPath( + toObject, + ['functionResponse'], + functionResponseToMldev(fromFunctionResponse), + ); + } + const fromCodeExecutionResult = common.getValueByPath(fromObject, [ 'codeExecutionResult', ]); @@ -170,13 +214,6 @@ export function partToMldev(fromObject: types.Part): Record { common.setValueByPath(toObject, ['executableCode'], fromExecutableCode); } - const fromFunctionResponse = common.getValueByPath(fromObject, [ - 'functionResponse', - ]); - if (fromFunctionResponse != null) { - common.setValueByPath(toObject, ['functionResponse'], fromFunctionResponse); - } - const fromText = common.getValueByPath(fromObject, ['text']); if (fromText != null) { common.setValueByPath(toObject, ['text'], fromText); @@ -1746,6 +1783,39 @@ export function functionCallFromMldev( return toObject; } +export function functionResponseFromMldev( + fromObject: types.FunctionResponse, +): Record { + const toObject: Record = {}; + + const fromWillContinue = common.getValueByPath(fromObject, ['willContinue']); + if (fromWillContinue != null) { + common.setValueByPath(toObject, ['willContinue'], fromWillContinue); + } + + const fromScheduling = common.getValueByPath(fromObject, ['scheduling']); + if (fromScheduling != null) { + common.setValueByPath(toObject, ['scheduling'], fromScheduling); + } + + const fromId = common.getValueByPath(fromObject, ['id']); + if (fromId != null) { + common.setValueByPath(toObject, ['id'], fromId); + } + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['name'], fromName); + } + + const fromResponse = common.getValueByPath(fromObject, ['response']); + if (fromResponse != null) { + common.setValueByPath(toObject, ['response'], fromResponse); + } + + return toObject; +} + export function partFromMldev(fromObject: types.Part): Record { const toObject: Record = {}; @@ -1799,6 +1869,17 @@ export function partFromMldev(fromObject: types.Part): Record { ); } + const fromFunctionResponse = common.getValueByPath(fromObject, [ + 'functionResponse', + ]); + if (fromFunctionResponse != null) { + common.setValueByPath( + toObject, + ['functionResponse'], + functionResponseFromMldev(fromFunctionResponse), + ); + } + const fromCodeExecutionResult = common.getValueByPath(fromObject, [ 'codeExecutionResult', ]); @@ -1817,13 +1898,6 @@ export function partFromMldev(fromObject: types.Part): Record { common.setValueByPath(toObject, ['executableCode'], fromExecutableCode); } - const fromFunctionResponse = common.getValueByPath(fromObject, [ - 'functionResponse', - ]); - if (fromFunctionResponse != null) { - common.setValueByPath(toObject, ['functionResponse'], fromFunctionResponse); - } - const fromText = common.getValueByPath(fromObject, ['text']); if (fromText != null) { common.setValueByPath(toObject, ['text'], fromText); diff --git a/src/converters/_caches_converters.ts b/src/converters/_caches_converters.ts index 76da9e5b5..60c8964fd 100644 --- a/src/converters/_caches_converters.ts +++ b/src/converters/_caches_converters.ts @@ -99,6 +99,39 @@ export function functionCallToMldev( return toObject; } +export function functionResponseToMldev( + fromObject: types.FunctionResponse, +): Record { + const toObject: Record = {}; + + const fromWillContinue = common.getValueByPath(fromObject, ['willContinue']); + if (fromWillContinue != null) { + common.setValueByPath(toObject, ['willContinue'], fromWillContinue); + } + + const fromScheduling = common.getValueByPath(fromObject, ['scheduling']); + if (fromScheduling != null) { + common.setValueByPath(toObject, ['scheduling'], fromScheduling); + } + + const fromId = common.getValueByPath(fromObject, ['id']); + if (fromId != null) { + common.setValueByPath(toObject, ['id'], fromId); + } + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['name'], fromName); + } + + const fromResponse = common.getValueByPath(fromObject, ['response']); + if (fromResponse != null) { + common.setValueByPath(toObject, ['response'], fromResponse); + } + + return toObject; +} + export function partToMldev(fromObject: types.Part): Record { const toObject: Record = {}; @@ -152,6 +185,17 @@ export function partToMldev(fromObject: types.Part): Record { ); } + const fromFunctionResponse = common.getValueByPath(fromObject, [ + 'functionResponse', + ]); + if (fromFunctionResponse != null) { + common.setValueByPath( + toObject, + ['functionResponse'], + functionResponseToMldev(fromFunctionResponse), + ); + } + const fromCodeExecutionResult = common.getValueByPath(fromObject, [ 'codeExecutionResult', ]); @@ -170,13 +214,6 @@ export function partToMldev(fromObject: types.Part): Record { common.setValueByPath(toObject, ['executableCode'], fromExecutableCode); } - const fromFunctionResponse = common.getValueByPath(fromObject, [ - 'functionResponse', - ]); - if (fromFunctionResponse != null) { - common.setValueByPath(toObject, ['functionResponse'], fromFunctionResponse); - } - const fromText = common.getValueByPath(fromObject, ['text']); if (fromText != null) { common.setValueByPath(toObject, ['text'], fromText); @@ -844,6 +881,39 @@ export function functionCallToVertex( return toObject; } +export function functionResponseToVertex( + fromObject: types.FunctionResponse, +): Record { + const toObject: Record = {}; + + const fromWillContinue = common.getValueByPath(fromObject, ['willContinue']); + if (fromWillContinue != null) { + common.setValueByPath(toObject, ['willContinue'], fromWillContinue); + } + + const fromScheduling = common.getValueByPath(fromObject, ['scheduling']); + if (fromScheduling != null) { + common.setValueByPath(toObject, ['scheduling'], fromScheduling); + } + + const fromId = common.getValueByPath(fromObject, ['id']); + if (fromId != null) { + common.setValueByPath(toObject, ['id'], fromId); + } + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['name'], fromName); + } + + const fromResponse = common.getValueByPath(fromObject, ['response']); + if (fromResponse != null) { + common.setValueByPath(toObject, ['response'], fromResponse); + } + + return toObject; +} + export function partToVertex(fromObject: types.Part): Record { const toObject: Record = {}; @@ -897,6 +967,17 @@ export function partToVertex(fromObject: types.Part): Record { ); } + const fromFunctionResponse = common.getValueByPath(fromObject, [ + 'functionResponse', + ]); + if (fromFunctionResponse != null) { + common.setValueByPath( + toObject, + ['functionResponse'], + functionResponseToVertex(fromFunctionResponse), + ); + } + const fromCodeExecutionResult = common.getValueByPath(fromObject, [ 'codeExecutionResult', ]); @@ -915,13 +996,6 @@ export function partToVertex(fromObject: types.Part): Record { common.setValueByPath(toObject, ['executableCode'], fromExecutableCode); } - const fromFunctionResponse = common.getValueByPath(fromObject, [ - 'functionResponse', - ]); - if (fromFunctionResponse != null) { - common.setValueByPath(toObject, ['functionResponse'], fromFunctionResponse); - } - const fromText = common.getValueByPath(fromObject, ['text']); if (fromText != null) { common.setValueByPath(toObject, ['text'], fromText); diff --git a/src/converters/_live_converters.ts b/src/converters/_live_converters.ts index b390ea421..26b4f8174 100644 --- a/src/converters/_live_converters.ts +++ b/src/converters/_live_converters.ts @@ -207,6 +207,39 @@ export function functionCallToMldev( return toObject; } +export function functionResponseToMldev( + fromObject: types.FunctionResponse, +): Record { + const toObject: Record = {}; + + const fromWillContinue = common.getValueByPath(fromObject, ['willContinue']); + if (fromWillContinue != null) { + common.setValueByPath(toObject, ['willContinue'], fromWillContinue); + } + + const fromScheduling = common.getValueByPath(fromObject, ['scheduling']); + if (fromScheduling != null) { + common.setValueByPath(toObject, ['scheduling'], fromScheduling); + } + + const fromId = common.getValueByPath(fromObject, ['id']); + if (fromId != null) { + common.setValueByPath(toObject, ['id'], fromId); + } + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['name'], fromName); + } + + const fromResponse = common.getValueByPath(fromObject, ['response']); + if (fromResponse != null) { + common.setValueByPath(toObject, ['response'], fromResponse); + } + + return toObject; +} + export function partToMldev(fromObject: types.Part): Record { const toObject: Record = {}; @@ -260,6 +293,17 @@ export function partToMldev(fromObject: types.Part): Record { ); } + const fromFunctionResponse = common.getValueByPath(fromObject, [ + 'functionResponse', + ]); + if (fromFunctionResponse != null) { + common.setValueByPath( + toObject, + ['functionResponse'], + functionResponseToMldev(fromFunctionResponse), + ); + } + const fromCodeExecutionResult = common.getValueByPath(fromObject, [ 'codeExecutionResult', ]); @@ -278,13 +322,6 @@ export function partToMldev(fromObject: types.Part): Record { common.setValueByPath(toObject, ['executableCode'], fromExecutableCode); } - const fromFunctionResponse = common.getValueByPath(fromObject, [ - 'functionResponse', - ]); - if (fromFunctionResponse != null) { - common.setValueByPath(toObject, ['functionResponse'], fromFunctionResponse); - } - const fromText = common.getValueByPath(fromObject, ['text']); if (fromText != null) { common.setValueByPath(toObject, ['text'], fromText); @@ -1172,39 +1209,6 @@ export function liveClientRealtimeInputToMldev( return toObject; } -export function functionResponseToMldev( - fromObject: types.FunctionResponse, -): Record { - const toObject: Record = {}; - - const fromWillContinue = common.getValueByPath(fromObject, ['willContinue']); - if (fromWillContinue != null) { - common.setValueByPath(toObject, ['willContinue'], fromWillContinue); - } - - const fromScheduling = common.getValueByPath(fromObject, ['scheduling']); - if (fromScheduling != null) { - common.setValueByPath(toObject, ['scheduling'], fromScheduling); - } - - const fromId = common.getValueByPath(fromObject, ['id']); - if (fromId != null) { - common.setValueByPath(toObject, ['id'], fromId); - } - - const fromName = common.getValueByPath(fromObject, ['name']); - if (fromName != null) { - common.setValueByPath(toObject, ['name'], fromName); - } - - const fromResponse = common.getValueByPath(fromObject, ['response']); - if (fromResponse != null) { - common.setValueByPath(toObject, ['response'], fromResponse); - } - - return toObject; -} - export function liveClientToolResponseToMldev( fromObject: types.LiveClientToolResponse, ): Record { @@ -1658,6 +1662,39 @@ export function functionCallToVertex( return toObject; } +export function functionResponseToVertex( + fromObject: types.FunctionResponse, +): Record { + const toObject: Record = {}; + + const fromWillContinue = common.getValueByPath(fromObject, ['willContinue']); + if (fromWillContinue != null) { + common.setValueByPath(toObject, ['willContinue'], fromWillContinue); + } + + const fromScheduling = common.getValueByPath(fromObject, ['scheduling']); + if (fromScheduling != null) { + common.setValueByPath(toObject, ['scheduling'], fromScheduling); + } + + const fromId = common.getValueByPath(fromObject, ['id']); + if (fromId != null) { + common.setValueByPath(toObject, ['id'], fromId); + } + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['name'], fromName); + } + + const fromResponse = common.getValueByPath(fromObject, ['response']); + if (fromResponse != null) { + common.setValueByPath(toObject, ['response'], fromResponse); + } + + return toObject; +} + export function partToVertex(fromObject: types.Part): Record { const toObject: Record = {}; @@ -1711,6 +1748,17 @@ export function partToVertex(fromObject: types.Part): Record { ); } + const fromFunctionResponse = common.getValueByPath(fromObject, [ + 'functionResponse', + ]); + if (fromFunctionResponse != null) { + common.setValueByPath( + toObject, + ['functionResponse'], + functionResponseToVertex(fromFunctionResponse), + ); + } + const fromCodeExecutionResult = common.getValueByPath(fromObject, [ 'codeExecutionResult', ]); @@ -1729,13 +1777,6 @@ export function partToVertex(fromObject: types.Part): Record { common.setValueByPath(toObject, ['executableCode'], fromExecutableCode); } - const fromFunctionResponse = common.getValueByPath(fromObject, [ - 'functionResponse', - ]); - if (fromFunctionResponse != null) { - common.setValueByPath(toObject, ['functionResponse'], fromFunctionResponse); - } - const fromText = common.getValueByPath(fromObject, ['text']); if (fromText != null) { common.setValueByPath(toObject, ['text'], fromText); @@ -2731,37 +2772,6 @@ export function liveClientRealtimeInputToVertex( return toObject; } -export function functionResponseToVertex( - fromObject: types.FunctionResponse, -): Record { - const toObject: Record = {}; - - if (common.getValueByPath(fromObject, ['willContinue']) !== undefined) { - throw new Error('willContinue parameter is not supported in Vertex AI.'); - } - - if (common.getValueByPath(fromObject, ['scheduling']) !== undefined) { - throw new Error('scheduling parameter is not supported in Vertex AI.'); - } - - const fromId = common.getValueByPath(fromObject, ['id']); - if (fromId != null) { - common.setValueByPath(toObject, ['id'], fromId); - } - - const fromName = common.getValueByPath(fromObject, ['name']); - if (fromName != null) { - common.setValueByPath(toObject, ['name'], fromName); - } - - const fromResponse = common.getValueByPath(fromObject, ['response']); - if (fromResponse != null) { - common.setValueByPath(toObject, ['response'], fromResponse); - } - - return toObject; -} - export function liveClientToolResponseToVertex( fromObject: types.LiveClientToolResponse, ): Record { @@ -2989,6 +2999,39 @@ export function functionCallFromMldev( return toObject; } +export function functionResponseFromMldev( + fromObject: types.FunctionResponse, +): Record { + const toObject: Record = {}; + + const fromWillContinue = common.getValueByPath(fromObject, ['willContinue']); + if (fromWillContinue != null) { + common.setValueByPath(toObject, ['willContinue'], fromWillContinue); + } + + const fromScheduling = common.getValueByPath(fromObject, ['scheduling']); + if (fromScheduling != null) { + common.setValueByPath(toObject, ['scheduling'], fromScheduling); + } + + const fromId = common.getValueByPath(fromObject, ['id']); + if (fromId != null) { + common.setValueByPath(toObject, ['id'], fromId); + } + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['name'], fromName); + } + + const fromResponse = common.getValueByPath(fromObject, ['response']); + if (fromResponse != null) { + common.setValueByPath(toObject, ['response'], fromResponse); + } + + return toObject; +} + export function partFromMldev(fromObject: types.Part): Record { const toObject: Record = {}; @@ -3042,6 +3085,17 @@ export function partFromMldev(fromObject: types.Part): Record { ); } + const fromFunctionResponse = common.getValueByPath(fromObject, [ + 'functionResponse', + ]); + if (fromFunctionResponse != null) { + common.setValueByPath( + toObject, + ['functionResponse'], + functionResponseFromMldev(fromFunctionResponse), + ); + } + const fromCodeExecutionResult = common.getValueByPath(fromObject, [ 'codeExecutionResult', ]); @@ -3060,13 +3114,6 @@ export function partFromMldev(fromObject: types.Part): Record { common.setValueByPath(toObject, ['executableCode'], fromExecutableCode); } - const fromFunctionResponse = common.getValueByPath(fromObject, [ - 'functionResponse', - ]); - if (fromFunctionResponse != null) { - common.setValueByPath(toObject, ['functionResponse'], fromFunctionResponse); - } - const fromText = common.getValueByPath(fromObject, ['text']); if (fromText != null) { common.setValueByPath(toObject, ['text'], fromText); @@ -3925,6 +3972,39 @@ export function functionCallFromVertex( return toObject; } +export function functionResponseFromVertex( + fromObject: types.FunctionResponse, +): Record { + const toObject: Record = {}; + + const fromWillContinue = common.getValueByPath(fromObject, ['willContinue']); + if (fromWillContinue != null) { + common.setValueByPath(toObject, ['willContinue'], fromWillContinue); + } + + const fromScheduling = common.getValueByPath(fromObject, ['scheduling']); + if (fromScheduling != null) { + common.setValueByPath(toObject, ['scheduling'], fromScheduling); + } + + const fromId = common.getValueByPath(fromObject, ['id']); + if (fromId != null) { + common.setValueByPath(toObject, ['id'], fromId); + } + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['name'], fromName); + } + + const fromResponse = common.getValueByPath(fromObject, ['response']); + if (fromResponse != null) { + common.setValueByPath(toObject, ['response'], fromResponse); + } + + return toObject; +} + export function partFromVertex( fromObject: types.Part, ): Record { @@ -3980,6 +4060,17 @@ export function partFromVertex( ); } + const fromFunctionResponse = common.getValueByPath(fromObject, [ + 'functionResponse', + ]); + if (fromFunctionResponse != null) { + common.setValueByPath( + toObject, + ['functionResponse'], + functionResponseFromVertex(fromFunctionResponse), + ); + } + const fromCodeExecutionResult = common.getValueByPath(fromObject, [ 'codeExecutionResult', ]); @@ -3998,13 +4089,6 @@ export function partFromVertex( common.setValueByPath(toObject, ['executableCode'], fromExecutableCode); } - const fromFunctionResponse = common.getValueByPath(fromObject, [ - 'functionResponse', - ]); - if (fromFunctionResponse != null) { - common.setValueByPath(toObject, ['functionResponse'], fromFunctionResponse); - } - const fromText = common.getValueByPath(fromObject, ['text']); if (fromText != null) { common.setValueByPath(toObject, ['text'], fromText); diff --git a/src/converters/_models_converters.ts b/src/converters/_models_converters.ts index c66122b5f..8edcab37b 100644 --- a/src/converters/_models_converters.ts +++ b/src/converters/_models_converters.ts @@ -100,6 +100,39 @@ export function functionCallToMldev( return toObject; } +export function functionResponseToMldev( + fromObject: types.FunctionResponse, +): Record { + const toObject: Record = {}; + + const fromWillContinue = common.getValueByPath(fromObject, ['willContinue']); + if (fromWillContinue != null) { + common.setValueByPath(toObject, ['willContinue'], fromWillContinue); + } + + const fromScheduling = common.getValueByPath(fromObject, ['scheduling']); + if (fromScheduling != null) { + common.setValueByPath(toObject, ['scheduling'], fromScheduling); + } + + const fromId = common.getValueByPath(fromObject, ['id']); + if (fromId != null) { + common.setValueByPath(toObject, ['id'], fromId); + } + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['name'], fromName); + } + + const fromResponse = common.getValueByPath(fromObject, ['response']); + if (fromResponse != null) { + common.setValueByPath(toObject, ['response'], fromResponse); + } + + return toObject; +} + export function partToMldev(fromObject: types.Part): Record { const toObject: Record = {}; @@ -153,6 +186,17 @@ export function partToMldev(fromObject: types.Part): Record { ); } + const fromFunctionResponse = common.getValueByPath(fromObject, [ + 'functionResponse', + ]); + if (fromFunctionResponse != null) { + common.setValueByPath( + toObject, + ['functionResponse'], + functionResponseToMldev(fromFunctionResponse), + ); + } + const fromCodeExecutionResult = common.getValueByPath(fromObject, [ 'codeExecutionResult', ]); @@ -171,13 +215,6 @@ export function partToMldev(fromObject: types.Part): Record { common.setValueByPath(toObject, ['executableCode'], fromExecutableCode); } - const fromFunctionResponse = common.getValueByPath(fromObject, [ - 'functionResponse', - ]); - if (fromFunctionResponse != null) { - common.setValueByPath(toObject, ['functionResponse'], fromFunctionResponse); - } - const fromText = common.getValueByPath(fromObject, ['text']); if (fromText != null) { common.setValueByPath(toObject, ['text'], fromText); @@ -1860,6 +1897,39 @@ export function functionCallToVertex( return toObject; } +export function functionResponseToVertex( + fromObject: types.FunctionResponse, +): Record { + const toObject: Record = {}; + + const fromWillContinue = common.getValueByPath(fromObject, ['willContinue']); + if (fromWillContinue != null) { + common.setValueByPath(toObject, ['willContinue'], fromWillContinue); + } + + const fromScheduling = common.getValueByPath(fromObject, ['scheduling']); + if (fromScheduling != null) { + common.setValueByPath(toObject, ['scheduling'], fromScheduling); + } + + const fromId = common.getValueByPath(fromObject, ['id']); + if (fromId != null) { + common.setValueByPath(toObject, ['id'], fromId); + } + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['name'], fromName); + } + + const fromResponse = common.getValueByPath(fromObject, ['response']); + if (fromResponse != null) { + common.setValueByPath(toObject, ['response'], fromResponse); + } + + return toObject; +} + export function partToVertex(fromObject: types.Part): Record { const toObject: Record = {}; @@ -1913,6 +1983,17 @@ export function partToVertex(fromObject: types.Part): Record { ); } + const fromFunctionResponse = common.getValueByPath(fromObject, [ + 'functionResponse', + ]); + if (fromFunctionResponse != null) { + common.setValueByPath( + toObject, + ['functionResponse'], + functionResponseToVertex(fromFunctionResponse), + ); + } + const fromCodeExecutionResult = common.getValueByPath(fromObject, [ 'codeExecutionResult', ]); @@ -1931,13 +2012,6 @@ export function partToVertex(fromObject: types.Part): Record { common.setValueByPath(toObject, ['executableCode'], fromExecutableCode); } - const fromFunctionResponse = common.getValueByPath(fromObject, [ - 'functionResponse', - ]); - if (fromFunctionResponse != null) { - common.setValueByPath(toObject, ['functionResponse'], fromFunctionResponse); - } - const fromText = common.getValueByPath(fromObject, ['text']); if (fromText != null) { common.setValueByPath(toObject, ['text'], fromText); @@ -4755,6 +4829,39 @@ export function functionCallFromMldev( return toObject; } +export function functionResponseFromMldev( + fromObject: types.FunctionResponse, +): Record { + const toObject: Record = {}; + + const fromWillContinue = common.getValueByPath(fromObject, ['willContinue']); + if (fromWillContinue != null) { + common.setValueByPath(toObject, ['willContinue'], fromWillContinue); + } + + const fromScheduling = common.getValueByPath(fromObject, ['scheduling']); + if (fromScheduling != null) { + common.setValueByPath(toObject, ['scheduling'], fromScheduling); + } + + const fromId = common.getValueByPath(fromObject, ['id']); + if (fromId != null) { + common.setValueByPath(toObject, ['id'], fromId); + } + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['name'], fromName); + } + + const fromResponse = common.getValueByPath(fromObject, ['response']); + if (fromResponse != null) { + common.setValueByPath(toObject, ['response'], fromResponse); + } + + return toObject; +} + export function partFromMldev(fromObject: types.Part): Record { const toObject: Record = {}; @@ -4808,6 +4915,17 @@ export function partFromMldev(fromObject: types.Part): Record { ); } + const fromFunctionResponse = common.getValueByPath(fromObject, [ + 'functionResponse', + ]); + if (fromFunctionResponse != null) { + common.setValueByPath( + toObject, + ['functionResponse'], + functionResponseFromMldev(fromFunctionResponse), + ); + } + const fromCodeExecutionResult = common.getValueByPath(fromObject, [ 'codeExecutionResult', ]); @@ -4826,13 +4944,6 @@ export function partFromMldev(fromObject: types.Part): Record { common.setValueByPath(toObject, ['executableCode'], fromExecutableCode); } - const fromFunctionResponse = common.getValueByPath(fromObject, [ - 'functionResponse', - ]); - if (fromFunctionResponse != null) { - common.setValueByPath(toObject, ['functionResponse'], fromFunctionResponse); - } - const fromText = common.getValueByPath(fromObject, ['text']); if (fromText != null) { common.setValueByPath(toObject, ['text'], fromText); @@ -5600,6 +5711,39 @@ export function functionCallFromVertex( return toObject; } +export function functionResponseFromVertex( + fromObject: types.FunctionResponse, +): Record { + const toObject: Record = {}; + + const fromWillContinue = common.getValueByPath(fromObject, ['willContinue']); + if (fromWillContinue != null) { + common.setValueByPath(toObject, ['willContinue'], fromWillContinue); + } + + const fromScheduling = common.getValueByPath(fromObject, ['scheduling']); + if (fromScheduling != null) { + common.setValueByPath(toObject, ['scheduling'], fromScheduling); + } + + const fromId = common.getValueByPath(fromObject, ['id']); + if (fromId != null) { + common.setValueByPath(toObject, ['id'], fromId); + } + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['name'], fromName); + } + + const fromResponse = common.getValueByPath(fromObject, ['response']); + if (fromResponse != null) { + common.setValueByPath(toObject, ['response'], fromResponse); + } + + return toObject; +} + export function partFromVertex( fromObject: types.Part, ): Record { @@ -5655,6 +5799,17 @@ export function partFromVertex( ); } + const fromFunctionResponse = common.getValueByPath(fromObject, [ + 'functionResponse', + ]); + if (fromFunctionResponse != null) { + common.setValueByPath( + toObject, + ['functionResponse'], + functionResponseFromVertex(fromFunctionResponse), + ); + } + const fromCodeExecutionResult = common.getValueByPath(fromObject, [ 'codeExecutionResult', ]); @@ -5673,13 +5828,6 @@ export function partFromVertex( common.setValueByPath(toObject, ['executableCode'], fromExecutableCode); } - const fromFunctionResponse = common.getValueByPath(fromObject, [ - 'functionResponse', - ]); - if (fromFunctionResponse != null) { - common.setValueByPath(toObject, ['functionResponse'], fromFunctionResponse); - } - const fromText = common.getValueByPath(fromObject, ['text']); if (fromText != null) { common.setValueByPath(toObject, ['text'], fromText); diff --git a/src/converters/_tokens_converters.ts b/src/converters/_tokens_converters.ts index 20beb6c36..3dab83d72 100644 --- a/src/converters/_tokens_converters.ts +++ b/src/converters/_tokens_converters.ts @@ -207,6 +207,39 @@ export function functionCallToMldev( return toObject; } +export function functionResponseToMldev( + fromObject: types.FunctionResponse, +): Record { + const toObject: Record = {}; + + const fromWillContinue = common.getValueByPath(fromObject, ['willContinue']); + if (fromWillContinue != null) { + common.setValueByPath(toObject, ['willContinue'], fromWillContinue); + } + + const fromScheduling = common.getValueByPath(fromObject, ['scheduling']); + if (fromScheduling != null) { + common.setValueByPath(toObject, ['scheduling'], fromScheduling); + } + + const fromId = common.getValueByPath(fromObject, ['id']); + if (fromId != null) { + common.setValueByPath(toObject, ['id'], fromId); + } + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['name'], fromName); + } + + const fromResponse = common.getValueByPath(fromObject, ['response']); + if (fromResponse != null) { + common.setValueByPath(toObject, ['response'], fromResponse); + } + + return toObject; +} + export function partToMldev(fromObject: types.Part): Record { const toObject: Record = {}; @@ -260,6 +293,17 @@ export function partToMldev(fromObject: types.Part): Record { ); } + const fromFunctionResponse = common.getValueByPath(fromObject, [ + 'functionResponse', + ]); + if (fromFunctionResponse != null) { + common.setValueByPath( + toObject, + ['functionResponse'], + functionResponseToMldev(fromFunctionResponse), + ); + } + const fromCodeExecutionResult = common.getValueByPath(fromObject, [ 'codeExecutionResult', ]); @@ -278,13 +322,6 @@ export function partToMldev(fromObject: types.Part): Record { common.setValueByPath(toObject, ['executableCode'], fromExecutableCode); } - const fromFunctionResponse = common.getValueByPath(fromObject, [ - 'functionResponse', - ]); - if (fromFunctionResponse != null) { - common.setValueByPath(toObject, ['functionResponse'], fromFunctionResponse); - } - const fromText = common.getValueByPath(fromObject, ['text']); if (fromText != null) { common.setValueByPath(toObject, ['text'], fromText); diff --git a/src/types.ts b/src/types.ts index 3a2cedde1..07d82b674 100644 --- a/src/types.ts +++ b/src/types.ts @@ -540,6 +540,26 @@ export enum AdapterSize { ADAPTER_SIZE_THIRTY_TWO = 'ADAPTER_SIZE_THIRTY_TWO', } +/** Specifies how the response should be scheduled in the conversation. */ +export enum FunctionResponseScheduling { + /** + * This value is unused. + */ + SCHEDULING_UNSPECIFIED = 'SCHEDULING_UNSPECIFIED', + /** + * Only add the result to the conversation context, do not interrupt or trigger generation. + */ + SILENT = 'SILENT', + /** + * Add the result to the conversation context, and prompt to generate output without interrupting ongoing generation. + */ + WHEN_IDLE = 'WHEN_IDLE', + /** + * Add the result to the conversation context, interrupt ongoing generation and prompt to generate output. + */ + INTERRUPT = 'INTERRUPT', +} + /** Options for feature selection preference. */ export enum FeatureSelectionPreference { FEATURE_SELECTION_PREFERENCE_UNSPECIFIED = 'FEATURE_SELECTION_PREFERENCE_UNSPECIFIED', @@ -901,26 +921,6 @@ export enum TurnCoverage { TURN_INCLUDES_ALL_INPUT = 'TURN_INCLUDES_ALL_INPUT', } -/** Specifies how the response should be scheduled in the conversation. */ -export enum FunctionResponseScheduling { - /** - * This value is unused. - */ - SCHEDULING_UNSPECIFIED = 'SCHEDULING_UNSPECIFIED', - /** - * Only add the result to the conversation context, do not interrupt or trigger generation. - */ - SILENT = 'SILENT', - /** - * Add the result to the conversation context, and prompt to generate output without interrupting ongoing generation. - */ - WHEN_IDLE = 'WHEN_IDLE', - /** - * Add the result to the conversation context, interrupt ongoing generation and prompt to generate output. - */ - INTERRUPT = 'INTERRUPT', -} - /** Scale of the generated music. */ export enum Scale { /** @@ -1069,6 +1069,20 @@ export declare interface FunctionCall { name?: string; } +/** A function response. */ +export class FunctionResponse { + /** Signals that function call continues, and more responses will be returned, turning the function call into a generator. Is only applicable to NON_BLOCKING function calls (see FunctionDeclaration.behavior for details), ignored otherwise. If false, the default, future responses will not be considered. Is only applicable to NON_BLOCKING function calls, is ignored otherwise. If set to false, future responses will not be considered. It is allowed to return empty `response` with `will_continue=False` to signal that the function call is finished. */ + willContinue?: boolean; + /** Specifies how the response should be scheduled in the conversation. Only applicable to NON_BLOCKING function calls, is ignored otherwise. Defaults to WHEN_IDLE. */ + scheduling?: FunctionResponseScheduling; + /** Optional. The id of the function call this response is for. Populated by the client to match the corresponding function call `id`. */ + id?: string; + /** Required. The name of the function to call. Matches [FunctionDeclaration.name] and [FunctionCall.name]. */ + name?: string; + /** Required. The function response in JSON object format. Use "output" key to specify function output and "error" key to specify error details (if any). If "output" and "error" keys are not specified, then whole "response" is treated as function output. */ + response?: Record; +} + /** Result of executing the [ExecutableCode]. Only generated when using the [CodeExecution] tool, and always follows a `part` containing the [ExecutableCode]. */ export declare interface CodeExecutionResult { /** Required. Outcome of the code execution. */ @@ -1085,20 +1099,6 @@ export declare interface ExecutableCode { language?: Language; } -/** A function response. */ -export class FunctionResponse { - /** Signals that function call continues, and more responses will be returned, turning the function call into a generator. Is only applicable to NON_BLOCKING function calls (see FunctionDeclaration.behavior for details), ignored otherwise. If false, the default, future responses will not be considered. Is only applicable to NON_BLOCKING function calls, is ignored otherwise. If set to false, future responses will not be considered. It is allowed to return empty `response` with `will_continue=False` to signal that the function call is finished. */ - willContinue?: boolean; - /** Specifies how the response should be scheduled in the conversation. Only applicable to NON_BLOCKING function calls, is ignored otherwise. Defaults to WHEN_IDLE. */ - scheduling?: FunctionResponseScheduling; - /** Optional. The id of the function call this response is for. Populated by the client to match the corresponding function call `id`. */ - id?: string; - /** Required. The name of the function to call. Matches [FunctionDeclaration.name] and [FunctionCall.name]. */ - name?: string; - /** Required. The function response in JSON object format. Use "output" key to specify function output and "error" key to specify error details (if any). If "output" and "error" keys are not specified, then whole "response" is treated as function output. */ - response?: Record; -} - /** A datatype containing media content. Exactly one field within a Part should be set, representing the specific type @@ -1121,12 +1121,12 @@ export declare interface Part { representing the [FunctionDeclaration.name] and a structured JSON object containing the parameters and their values. */ functionCall?: FunctionCall; + /** Optional. The result output of a [FunctionCall] that contains a string representing the [FunctionDeclaration.name] and a structured JSON object containing any output from the function call. It is used as context to the model. */ + functionResponse?: FunctionResponse; /** Optional. Result of executing the [ExecutableCode]. */ codeExecutionResult?: CodeExecutionResult; /** Optional. Code generated by the model that is meant to be executed. */ executableCode?: ExecutableCode; - /** Optional. The result output of a [FunctionCall] that contains a string representing the [FunctionDeclaration.name] and a structured JSON object containing any output from the function call. It is used as context to the model. */ - functionResponse?: FunctionResponse; /** Optional. Text part (can be code). */ text?: string; }