({
pipe,
variables
}: {
pipe: Pipe;
variables?: VariablesI;
})
| 24 | } |
| 25 | |
| 26 | function getVarsMap({ |
| 27 | pipe, |
| 28 | variables |
| 29 | }: { |
| 30 | pipe: Pipe; |
| 31 | variables?: VariablesI; |
| 32 | }) { |
| 33 | const hasPipeVars = pipe.variables ? pipe.variables.length > 0 : false; |
| 34 | const hasCurrentPromptVars = variables ? variables.length > 0 : false; |
| 35 | |
| 36 | const pipeVars = hasPipeVars ? pipe.variables : []; |
| 37 | const currentPromptVars = hasCurrentPromptVars ? variables : []; |
| 38 | |
| 39 | let finalVariablesMap: Map<string, string> = new Map(); |
| 40 | |
| 41 | if (hasPipeVars) { |
| 42 | pipeVars.forEach((v: { name: string; value: string }) => |
| 43 | finalVariablesMap.set(v.name, v.value) |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | if (hasCurrentPromptVars) { |
| 48 | currentPromptVars?.forEach((v: VariableI) => |
| 49 | finalVariablesMap.set(v.name, v.value) |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | // Convert the map back to an array for debugging |
| 54 | let finalVariables: VariableI[] = Array.from( |
| 55 | finalVariablesMap, |
| 56 | ([name, value]) => ({ |
| 57 | name, |
| 58 | value |
| 59 | }) |
| 60 | ); |
| 61 | dlog(`finalVariables`, finalVariables); |
| 62 | |
| 63 | return finalVariablesMap; |
| 64 | } |
| 65 | |
| 66 | // Function to replace variables in the messages |
| 67 | function replaceVarsInMessagesWithVals({ |
no test coverage detected